diff --git a/NovetusLauncher/.vs/NovetusLauncher/v14/.suo b/NovetusLauncher/.vs/NovetusLauncher/v14/.suo index 58074e1..c08809e 100644 Binary files a/NovetusLauncher/.vs/NovetusLauncher/v14/.suo and b/NovetusLauncher/.vs/NovetusLauncher/v14/.suo differ 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()))