Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.Windows.Forms;
- namespace Launcher
- {
- class Program
- {
- static void Main(string[] args)
- {
- var launcher = new Launcher();
- launcher.RunApplication();
- }
- }
- class Launcher
- {
- static string AppData { get { return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } }
- const string FolderPath = "alt";
- readonly string BuildPath = $@"{AppData}\{FolderPath}\build.txt";
- readonly string AppPath = $@"{AppData}\{FolderPath}\app.exe";
- readonly string GetLatestApp = "http://IP/latest-alt.exe";
- readonly string GetLatestBuild = "http://IP/latest-build.txt";
- public void RunApplication()
- {
- if (!Directory.Exists($"{AppData}/{FolderPath}"))
- Directory.CreateDirectory($"{AppData}/{FolderPath}");
- if (UpdateAvailable())
- DownloadApplication();
- if (File.Exists(AppPath)) Process.Start(AppPath);
- else MessageBox.Show("При скачивании последней версии ALT'a возникли ошибки.\nПроверьте интернет соединение");
- }
- public bool UpdateAvailable()
- {
- if (!File.Exists(BuildPath) || !File.Exists(AppPath))
- return true;
- try {
- var serverBuild = new WebClient().DownloadString(GetLatestBuild);
- var localBuild = File.ReadAllText(BuildPath);
- return serverBuild != localBuild;
- } catch { return false; }
- }
- public void DownloadApplication()
- {
- try {
- var client = new WebClient();
- //File.Delete(AppPath);
- //File.Delete(BuildPath);
- client.DownloadFile(GetLatestApp, AppPath);
- client.DownloadFile(GetLatestBuild, BuildPath);
- } catch { }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement