Вообщем простой код , который удаляет и скачивает zip файл с нужным файлом для постоянного обновления , у меня это файл где находится текст игры.
Usually a simple code is required that processes and downloads a zip file with a file for regular updates, this file contains the text of the game.
Code:
InitializeComponent();
System.IO.File.Delete(@"data/db/T_Dialogue.ini");
var exePath = Environment.CurrentDirectory;
var bin = System.IO.Path.Combine(exePath, @"data\db");
try
{
WebClient webclient = new WebClient();
var path = System.IO.Path.Combine(bin, "Update.zip");
Uri uri = new Uri("http://127.0.0.1/Update.zip");
webclient.DownloadFileAsync(uri, path);
webclient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
webclient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
void webClient_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
{
label2.Text = "" + (Convert.ToDouble(e.BytesReceived) / 1024 / 1024).ToString("0,00") + " МБ" + " / " + (Convert.ToDouble(e.TotalBytesToReceive) / 1024 / 1024).ToString("0.00") + " МБ";
}
void webClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
Thread.Sleep(2000);
string sourceArchiveFileName = "Update.zip";
ZipFile.ExtractToDirectory(path, bin);
System.IO.File.Delete(path);
label2.Text = "Проверка обновлений завершена.";
var path_game = System.IO.Path.Combine(bin, "T_Dialogue.ini");
File.Create(path_game);
launchVindi();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}