Fixed downloader
This commit is contained in:
parent
b638c3b689
commit
c265ff3e5b
Binary file not shown.
|
|
@ -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,40 +77,15 @@ 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;
|
||||
processRequest(request, response, remoteStream, localStream, localFilename, bytesProcessed);
|
||||
}
|
||||
else
|
||||
{
|
||||
WebRequest request = WebRequest.Create(remoteFilename);
|
||||
processRequest(request, response, remoteStream, localStream, localFilename, bytesProcessed);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close the response and streams objects here
|
||||
// to make sure they're closed even if an exception
|
||||
// is thrown at some point
|
||||
if (response != null) response.Close();
|
||||
if (remoteStream != null) remoteStream.Close();
|
||||
if (localStream != null) localStream.Close();
|
||||
}
|
||||
|
||||
// Return total bytes processed to caller.
|
||||
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
|
||||
|
|
@ -144,6 +120,23 @@ class Downloader
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
downloadOutcomeException = " Exception detected: " + e.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close the response and streams objects here
|
||||
// to make sure they're closed even if an exception
|
||||
// is thrown at some point
|
||||
if (response != null) response.Close();
|
||||
if (remoteStream != null) remoteStream.Close();
|
||||
if (localStream != null) localStream.Close();
|
||||
}
|
||||
|
||||
// Return total bytes processed to caller.
|
||||
return bytesProcessed;
|
||||
}
|
||||
|
||||
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue