From c265ff3e5b5a6203a782438b3c070532c577d14b Mon Sep 17 00:00:00 2001 From: Bitl Date: Sat, 9 Nov 2019 10:52:05 -0700 Subject: [PATCH] Fixed downloader --- NovetusLauncher/.vs/NovetusLauncher/v14/.suo | Bin 161280 -> 159744 bytes NovetusLauncher/NovetusFuncs/Downloader.cs | 97 +++++++++---------- NovetusLauncher/NovetusLauncher/ItemMaker.cs | 8 +- 3 files changed, 49 insertions(+), 56 deletions(-) diff --git a/NovetusLauncher/.vs/NovetusLauncher/v14/.suo b/NovetusLauncher/.vs/NovetusLauncher/v14/.suo index 58074e1d873920a2364db258b7b8f7fa06d1cd2c..c08809eb99d0496733c187146da7444765703ebf 100644 GIT binary patch delta 2421 zcmd^>Uu;uV9LMkPtnIea?qAs-wr-Tt{bL)fW6TZ59Bd3S{=|_5fdD~*l1!M}V7d&U zQ^b%cvh@%SSrpg}Gy(%zuiAhlOdMfGlEnw&gAdjRL=bSqih_~)J>9J#B)s_Gi>LYA z-=Fil=iKu>C-=7Jc6?7TzPEIm5^YI}G6{YRcoYtYWtu?#P?Mcm?`reJl!Vz_~K zo4P5J|Hi`B87L`8leLNx%gK=LvBE0{7$PhOp9LlZIc5fIJjesGKNWT+m*DNp1E z5I?Kus$u7W8n8gmO^g^0*CDP4>mqsXbLaH6)!Nr1+8D`1>%!qpddz!sOKaN^bbxJO zJLm+jf!9Gdh~BmX{u^K?*abYG2YA_*_@2W96WgM7nmoj25WgRr=aK45)usA!6sf+n za+{*+OK~dn{B&4@?n~8Ox-Zq2DnF^d9P4rQAD~XEFY^%J^UtG4)t6f=JD;Y09QuoZ ze5g5k?Y~oB&caW+Gyjtv@S7dXkc{KVU1mpo3LG1F#Fv?~_+&%UP}^SeCu}!TmDXun z9>c#(8KNrQX?xf2axm^_by*f+t%>@2d0(2#7>D~udDE*)w2{_oQtfg648}CJ^b%R* z%H#${Rw!$wSc>)_ztEsLw+xU~S*Z6$D|l#YvF0d_i%GJT+h*L$P{(sGmRwkqlBe*> zS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-+~eh0h@-UEH09~=P#U=SPy$H4nw z2z&rO1joS%a1wk3P6M9#4D`p~6L1zc`5ifi6`#WX44elSz(w#m_yT+hz5n;IxPd{&=E26KnOp;_yi0`i z54kkg@{8nMCA^iw^e^TyhvvatyuNE_+WL-7ulrpCWTtXVml-wXq^K=u!CKP$R}YeD z3Mx{fs}NpV&Y||Mprd$Xd~~v#{bJ9(a@RX7Jdlc#DgL$ za^nB{LsI-_hlC&R|9nW~_yc3~uy$=@7WLR0@DQv&6r&9_danBO-DKT)q~AIBp19jw z_g`{P-efo_Jq1I)jimRLlV0uEPPTw;GyO!qO1O<%=`NLXkmd#UG*e@iuZD!8W?B`f zN*9Nw`&ObPQBj$)A0>03qFD4A_OGV#WktF&TysKK0bVJy@kzkf99Tv0^YLXd8?W1W zx>CSdPsl0_jav+x$In-%R?{riu!f|n8Kmq$&Ivjf8(QjlO7c|+A?xhcfb}w6CN*-H zPN-A6s7uv7PTjsyEVSAxW~+t8qDTcFqxitaowPs3H%1mUa)uVG-xiAOz(c!fUtA); zc*ElC%Y%`n`d*|G)tx6+sTa=D+`zCTyD8-J#*+(Gbvxw-Dl5c&lBSxpQD7sU$%WYTE0vYupK}h4~Qfb}n`AhPJ<##AM BYaajr diff --git a/NovetusLauncher/NovetusFuncs/Downloader.cs b/NovetusLauncher/NovetusFuncs/Downloader.cs index bdd9a4e..d2070b0 100644 --- a/NovetusLauncher/NovetusFuncs/Downloader.cs +++ b/NovetusLauncher/NovetusFuncs/Downloader.cs @@ -10,6 +10,7 @@ class Downloader private string fileFilter; private string downloadOutcome; private string downloadOutcomeAddText; + private static string downloadOutcomeException; private ProgressBar downloadProgress; private SaveFileDialog saveFileDialog1; @@ -31,7 +32,7 @@ class Downloader return downloadOutcome; } - public void InitDownload(bool gzip, string additionalText = "") + public void InitDownload(string additionalText = "") { downloadOutcomeAddText = additionalText; @@ -47,8 +48,8 @@ class Downloader { try { - int read = DownloadFile(fileURL, saveFileDialog1.FileName, gzip); - downloadOutcome = "File " + Path.GetFileName(saveFileDialog1.FileName) + " downloaded! " + read + " bytes written!" + downloadOutcomeAddText; + int read = DownloadFile(fileURL, saveFileDialog1.FileName); + downloadOutcome = "File " + Path.GetFileName(saveFileDialog1.FileName) + " downloaded! " + read + " bytes written! " + downloadOutcomeAddText + downloadOutcomeException; } catch (Exception ex) { @@ -57,7 +58,7 @@ class Downloader } } - private static int DownloadFile(string remoteFilename, string localFilename, bool gzip) + private static int DownloadFile(string remoteFilename, string localFilename) { //credit to Tom Archer (https://www.codeguru.com/columns/dotnettips/article.php/c7005/Downloading-Files-with-the-WebRequest-and-WebResponse-Classes.htm) //and Brokenglass (https://stackoverflow.com/questions/4567313/uncompressing-gzip-response-from-webclient/4567408#4567408) @@ -76,23 +77,52 @@ class Downloader // classes throw exceptions upon error try { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls + | SecurityProtocolType.Tls11 + | SecurityProtocolType.Tls12 + | SecurityProtocolType.Ssl3; // Create a request for the specified remote file name - if (gzip) + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(remoteFilename); + request.UserAgent = "Roblox/WinINet"; + request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); + request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + if (request != null) { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(remoteFilename); - request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); - request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; - processRequest(request, response, remoteStream, localStream, localFilename, bytesProcessed); - } - else - { - WebRequest request = WebRequest.Create(remoteFilename); - processRequest(request, response, remoteStream, localStream, localFilename, bytesProcessed); + // Send the request to the server and retrieve the + // WebResponse object + response = request.GetResponse(); + if (response != null) + { + // Once the WebResponse object has been retrieved, + // get the stream object associated with the response's data + remoteStream = response.GetResponseStream(); + + // Create the local file + localStream = File.Create(localFilename); + + // Allocate a 1k buffer + byte[] buffer = new byte[1024]; + int bytesRead; + + // Simple do/while loop to read from stream until + // no bytes are returned + do + { + // Read data (up to 1k) from the stream + bytesRead = remoteStream.Read(buffer, 0, buffer.Length); + + // Write the data to the local file + localStream.Write(buffer, 0, bytesRead); + + // Increment total bytes processed + bytesProcessed += bytesRead; + } while (bytesRead > 0); + } } } catch (Exception e) { - Console.WriteLine(e.Message); + downloadOutcomeException = " Exception detected: " + e.Message; } finally { @@ -108,43 +138,6 @@ class Downloader return bytesProcessed; } - private static void processRequest(WebRequest request, WebResponse response, Stream remoteStream, Stream localStream, string localFilename, int bytesProcessed) - { - if (request != null) - { - // Send the request to the server and retrieve the - // WebResponse object - response = request.GetResponse(); - if (response != null) - { - // Once the WebResponse object has been retrieved, - // get the stream object associated with the response's data - remoteStream = response.GetResponseStream(); - - // Create the local file - localStream = File.Create(localFilename); - - // Allocate a 1k buffer - byte[] buffer = new byte[1024]; - int bytesRead; - - // Simple do/while loop to read from stream until - // no bytes are returned - do - { - // Read data (up to 1k) from the stream - bytesRead = remoteStream.Read(buffer, 0, buffer.Length); - - // Write the data to the local file - localStream.Write(buffer, 0, bytesRead); - - // Increment total bytes processed - bytesProcessed += bytesRead; - } while (bytesRead > 0); - } - } - } - void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { downloadProgress.Value = e.ProgressPercentage; diff --git a/NovetusLauncher/NovetusLauncher/ItemMaker.cs b/NovetusLauncher/NovetusLauncher/ItemMaker.cs index 059289d..c127a0e 100644 --- a/NovetusLauncher/NovetusLauncher/ItemMaker.cs +++ b/NovetusLauncher/NovetusLauncher/ItemMaker.cs @@ -42,22 +42,22 @@ namespace NovetusLauncher if (!isWebSite) { - Downloader download = new Downloader(fullURL, textBox1.Text, "Roblox Model (*.rbxm)|*.rbxm|Roblox Mesh (*.mesh)|*.mesh|PNG Image (*.png)|*.png|WAV Sound (*.wav)|*.wav", progressBar1); - if (!GlobalVars.DisabledHelp) { string helptext = "If you're trying to create a offline item, please use these file extension names when saving your files:\n.rbxm - ROBLOX Model/Item\n.mesh - ROBLOX Mesh\n.png - Texture/Icon\n.wav - Sound"; MessageBox.Show(helptext, "Novetus Item SDK", MessageBoxButtons.OK, MessageBoxIcon.Information); } + Downloader download = new Downloader(fullURL, textBox1.Text, "Roblox Model (*.rbxm)|*.rbxm|Roblox Mesh (*.mesh)|*.mesh|PNG Image (*.png)|*.png|WAV Sound (*.wav)|*.wav", progressBar1); try { string helptext = "In order for the item to work in Novetus, you'll need to find an icon for your item (it must be a .png file), then name it the same name as your item.\n\nIf you want to create a local (offline) item, you'll have to download the meshes/textures from the links in the rbxm file, then replace the links in the file pointing to where they are using rbxasset://. Look at the directory in the 'shareddata/charcustom' folder that best suits your item type, then look at the rbxm for any one of the items. If you get a corrupted file, change the URL using the drop down box."; - download.InitDownload(true, (!GlobalVars.DisabledHelp) ? helptext : ""); + download.InitDownload((!GlobalVars.DisabledHelp) ? helptext : ""); } - catch (Exception) + catch (Exception ex) { + MessageBox.Show("Error: Unable to download the file. " +ex.Message, "Novetus Item SDK | Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!string.IsNullOrWhiteSpace(download.getDownloadOutcome()))