AutID Posted April 6, 2015 Share Posted April 6, 2015 Some time ago i had created a function in C# and i need it know for a project i am working on in Autoit. The code looks like this expandcollapse popupstatic void _Stream(string sUrl, string existingFilename) { HttpWebRequest webRequest; HttpWebResponse webResponse; IWebProxy proxy = null; //SA??? FileStream fs = null; try { string fname = existingFilename; if (fname == null) fname = ConvertUrlToFileName(sUrl); No need translation webRequest = (HttpWebRequest)WebRequest.Create(sUrl); long preloadedLength = GetExistingFileLength(fname); No need translation if (preloadedLength > 0) webRequest.AddRange((int)preloadedLength); webRequest.Proxy = proxy; webResponse = (HttpWebResponse)webRequest.GetResponse(); fs = new FileStream( fname, FileMode.Append, FileAccess.Write); long fileLength = webResponse.ContentLength; Stream strm = webResponse.GetResponseStream(); int arrSize = 10 * 1024 * 1024; //SA??? byte[] barr = new byte[arrSize]; long bytesCounter = preloadedLength; string fmtPercent = string.Empty; while (true) { int actualBytes = strm.Read(barr, 0, arrSize); if (actualBytes <= 0) break; fs.Write(barr, 0, actualBytes); bytesCounter += actualBytes; double percent = 0d; if (fileLength > 0) percent = 100.0d * bytesCounter / (preloadedLength + fileLength); } } catch (Exception e) { //do nothing } finally { if (fs != null) { fs.Flush(); fs.Close(); } //if } } Can someone help me translate this code to autoit. I gave it a try but it was a total failure so i am not willing to share it here... https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
JohnOne Posted April 6, 2015 Share Posted April 6, 2015 Please add comments to the code to describe exactly what each line is doing. Be easier to translate then. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
guinness Posted April 6, 2015 Share Posted April 6, 2015 You want WinHttp. Look in the Examples section. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jvanegmond Posted April 7, 2015 Share Posted April 7, 2015 This looks like a poor implementation of the AutoIt InetGet function with some non-functional code related to progress measurement, which InetGet can do. github.com/jvanegmond Link to comment Share on other sites More sharing options...
AutID Posted April 7, 2015 Author Share Posted April 7, 2015 Please add comments to the code to describe exactly what each line is doing. Be easier to translate then. If you know C# then i belive it is easy to understand what the code is doing. You want WinHttp. Look in the Examples section. I know but i have difficult time understanding winhttp.au3. I like trancexx but the udf is simply beyond what i usually do. This looks like a poor implementation of the AutoIt InetGet function with some non-functional code related to progress measurement, which InetGet can do. I know. It is not the entire code. Just a small sample. The part that i am having difficulties to translate. I don't want to use INetGet for some reasons. https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
JohnOne Posted April 7, 2015 Share Posted April 7, 2015 (edited) If you know C# then i belive it is easy to understand what the code is doing. I know that, but it will be much simpler with your comments in the code, then people who don't know C# can help too, I assume help is what you want here, and it wont take you a few minutes to write the cooments. You did write that code right? Edited April 7, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jvanegmond Posted April 8, 2015 Share Posted April 8, 2015 It is entirely irrelevant if he wrote the code or not. @OP, you do want WinHttp unfortunately. The help file on that is pretty good so it should be doable.If you have this code as part of a working program, you can use Wireshark or Fiddler (I see parts of proxy support in there which is how Fiddler captures traffic) to capture the traffic then compare it with your own attempts at generating a valid HTTP request and reading the response. github.com/jvanegmond Link to comment Share on other sites More sharing options...
JohnOne Posted April 8, 2015 Share Posted April 8, 2015 I'm just pointing out that it is simple to write comments on code you create, and it would speed up the help. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AutID Posted April 8, 2015 Author Share Posted April 8, 2015 I am not trying to figure out the traffic or understand what the code does. It is clear what the code does. I want to translate it to autoit and then modify it somehow. However i have been trying for hours and i fail badly. I have very low http knowledge. I am shooting in the dark here... https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
JohnOne Posted April 8, 2015 Share Posted April 8, 2015 I see, sorry, I though you understood it because you created it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
guinness Posted April 8, 2015 Share Posted April 8, 2015 (edited) It's polite to link or attribute to the person(s) who wrote that code. Otherwise we all think you know what you're doing. Edit: Oh and the whole "I have been trying for hours comment" doesn't work around here. Do us a favour and show us the fruits of your "hard" labour. Edited April 8, 2015 by guinness MuffettsMan 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
AutID Posted April 8, 2015 Author Share Posted April 8, 2015 (edited) I see, sorry, I though you understood it because you created it. I understand it but translating it is difficult for me because i dont understand winhttp.au3. C# has nothing to do with autoit and C++. You must know it... It's polite to link or attribute to the person(s) who wrote that code. Otherwise we all think you know what you're doing. Edit: Oh and the whole "I have been trying for hours comment" doesn't work around here. Do us a favour and show us the fruits of your "hard" labour. Remind me when i forced you to help me and i will apologise. If i simply wanted to download a file with winhttp.au3 i would have already done it without even posting here. The reason i am posting is because i want an exact translate of my code. Not for actual use but for some other reason that i could probably tell you but i won't because i know the only reason you are here in this thread is because you are curious and you want some attention. Go get a pet, it will work trust me. Edit: Oh and the whole "i want to help but i only ask questions" doesn't work with me. Go play somewhere else please. Edited April 8, 2015 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
JohnOne Posted April 8, 2015 Share Posted April 8, 2015 I understand it but translating it is difficult for me because i dont understand winhttp.au3. C# has nothing to do with autoit and C++. You must know it... If you understand it, please do yourself a favour and just comment what each line is doing. How hard can it be? It will be easier for others to translate. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 8, 2015 Developers Share Posted April 8, 2015 I understand it but translating it is difficult for me because i dont understand winhttp.au3. C# has nothing to do with autoit and C++. You must know it... Remind me when i forced you to help me and i will apologise. If i simply wanted to download a file with winhttp.au3 i would have already done it without even posting here. The reason i am posting is because i want an exact translate of my code. Not for actual use but for some other reason that i could probably tell you but i won't because i know the only reason you are here in this thread is because you are curious and you want some attention. Go get a pet, it will work trust me. Edit: Oh and the whole "i want to help but i only ask questions" doesn't work with me. Go play somewhere else please. You are now way out of line ... next post like this will get this locked! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
AutID Posted April 8, 2015 Author Share Posted April 8, 2015 (edited) You are now way out of line ... next post like this will get this locked! Jos My apologies. Anyway, i no need help with this anymore. Thank you everybody. Edited April 8, 2015 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now