-1
I’m making an online installer for my Github program, I made a Form with some basic controls.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.IO.Compression;
using System.Reflection;
namespace IEIPInstaller
{
public partial class Main : Form
{
private string temp = Path.Combine(Path.GetTempPath(), "IEIPInst");
private string localProg = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public Main()
{
if (Directory.Exists(temp))
{
if(File.Exists(temp + "\\IEIPv0.2-alpha-Windows.zip"))
{
File.Delete(temp + "\\IEIPv0.2-alpha-Windows.zip");
}
Directory.Delete(temp);
}
if(File.Exists(localProg + "\\IEIPv0.2-alpha-Windows.zip"))
{
MessageBox.Show("Installer cannot be initialized because you have IEIP with this program.", "IEIPInst", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
else
{
InitializeComponent();
Directory.CreateDirectory(temp);
}
}
private void btnNo_Click(object sender, EventArgs e)
{
Directory.Delete(temp, true);
Application.Exit();
}
private void btnYes_Click(object sender, EventArgs e)
{
btnYes.Enabled = false;
btnNo.Enabled = false;
lblWant.Text = "";
Complete.Text = "Status: Connecting...";
startDownload();
}
private void startDownload()
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("https://github.com/JPPlaysGamer/IndustriesExes.Inc/releases/download/ieip-pre2/IEIPv0.2-alpha-Windows.zip"), temp + "\\IEIPv0.2-alpha-Windows.zip");
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate {
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
Mbs.Text = (bytesIn / 1024 / 1024).ToString("F2") + " / " + (totalBytes / 1024/ 1024).ToString("F2") + " Mb";
Complete.Text = "Status: Downloading...";
IEIPProgress.Value = int.Parse(Math.Truncate(percentage).ToString());
this.Text = "IEIP Installer - " + IEIPProgress.Value + "%";
});
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate {
if(File.Exists(temp + "\\IEIPv0.2-alpha-Windows.zip"))
{
File.Move(temp + "\\IEIPv0.2-alpha-Windows.zip", localProg + "\\IEIPv0.2-alpha-Windows.zip");
}
Complete.Text = "Status: Completed";
btnNo.Text = "Exit";
btnNo.Enabled = true;
});
}
}
}
In JIT:
This is the structure of this Form and in the client_DownloadFileCompleted function wanted to make you unzip the zip file that shows in the code. But as I am using . NET 3.5 (version embedded in Windows, I think) does not have the class System.IO.Compression.Zipfile and works only on . recent NET. But there’s the Gzipstream class that can handle Zip. Is there any way to zip and unzip files with this class or with some Nuget library (or Github)?
according to the documentation, there is no version 3.5: https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile?view=net-5.0 can use another package for this, a fez q zip is a standard format, for example https://github.com/iccode/SharpZipLib
– Ricardo Pontual
This Sharpziplib can work in this version?
– João Paulo
look there in the link releases to answer this question :)
– Ricardo Pontual
I have my Visualstudio open and I found the Nuget Pack, and there is no need to test this package
– João Paulo
Unable to use Sharpziplib :(
– João Paulo