public static async Task <bool> EnsureLatestInstalled(string path) { string latestInfo = DownloadForm.DownloadString("Checking for sampctl update...", "http://api.github.com/repos/Southclaws/sampctl/releases/latest"); var mtch = Regex.Match(latestInfo, "\"tag_name\":\"(?<version>.+?)\","); string version = mtch.Groups["version"].Value; //If exists and different version, download, else keep. if (File.Exists(Path.Combine(path, "sampctl.exe")) == false || (File.Exists(Path.Combine(path, "sampctl.exe")) && await GetCurrentVersion(Path.Combine(path, "sampctl.exe")) != version)) { string arch = Environment.Is64BitOperatingSystem ? "amd64" : "386"; string fileToDownload = $@"https://github.com/Southclaws/sampctl/releases/download/{version}/sampctl_{version}_windows_{arch}.tar.gz"; DownloadForm.DownloadFile("Downloading SampCTL...", fileToDownload, Path.Combine(path, "archive.tar.gz")); GeneralFunctions.FastZipUnpack(Path.Combine(path, "archive.tar.gz"), path, "sampctl.exe"); File.Delete(Path.Combine(path, "archive.tar.gz")); } return(true); }
private async void StartupForm_Load(object sender, EventArgs e) { //Download SAMPCTL await SampCtl.EnsureLatestInstalled(Application.StartupPath); //Add event. pathTextBox.PathText.TextChanged += pathTextBox_TextChanged; //Check for updates AutoUpdater.ParseUpdateInfoEvent += AutoUpdater_ParseUpdateInfoEvent; DownloadForm.DownloadFile(translations.StartupForm_StartupForm_Load_Checking_for_updates, "https://api.github.com/repos/Ahmad45123/ExtremeStudio/releases/latest", Application.StartupPath + "/latest.txt"); AutoUpdater.Start(Application.StartupPath + "/latest.txt"); //If the interop files don't exist, Extract the files. /*if (IsFirst && * (!File.Exists( * Application.StartupPath + "/x64/SQLite.Interop.dll") || * !File.Exists( * Application.StartupPath + "/x86/SQLite.Interop.dll"))) * { * //Remove old. * if (File.Exists( * Application.StartupPath + "/x64/SQLite.Interop.dll")) * { * File.Delete( * Application.StartupPath + "/x64/SQLite.Interop.dll"); * } * * if (File.Exists( * Application.StartupPath + "/x86/SQLite.Interop.dll")) * { * File.Delete( * Application.StartupPath + "/x86/SQLite.Interop.dll"); * } * * //Extract New * File.WriteAllBytes( * Application.StartupPath + "/interop.zip", Properties.Resources.SQLite_Interop); //Write the file. * GeneralFunctions.FastZipUnpack(Application.StartupPath + "/interop.zip", * Application.StartupPath); //Extract it. * File.Delete( * Application.StartupPath + "/interop.zip"); //Delete the temp file. * }*/ //Create needed folders and files. if (!Directory.Exists( Application.StartupPath + "/cache")) { Directory.CreateDirectory( Application.StartupPath + "/cache"); } if (!Directory.Exists( Application.StartupPath + "/cache/serverPackages")) { Directory.CreateDirectory( Application.StartupPath + "/cache/serverPackages"); } if (!Directory.Exists( Application.StartupPath + "/cache/includes")) { Directory.CreateDirectory( Application.StartupPath + "/cache/includes"); } if (!Directory.Exists( Application.StartupPath + "/configs")) { Directory.CreateDirectory( Application.StartupPath + "/configs"); File.WriteAllText( Application.StartupPath + "/configs/recent.json", ""); } //Setting the IsGlobal in Settings will make sure the settings are in place and correct. Program.SettingsForm.IsGlobal = true; //Load all the recent. if (File.Exists( Application.StartupPath + "/configs/recent.json")) { try { Recent = JsonConvert.DeserializeObject <List <string> >( File.ReadAllText( Application.StartupPath + "/configs/recent.json")); if (ReferenceEquals(Recent, null)) { Recent = new List <string>(); } } catch (Exception) { } } if (ProjectToOpen != "") { if (GeneralFunctions.IsValidExtremeProject(ProjectToOpen)) { Program.MainForm.CurrentProject.ProjectPath = ProjectToOpen; Program.MainForm.CurrentProject.ReadInfo(); projectName.Text = Program.MainForm.CurrentProject.ProjectName; string projVersion = Convert.ToString(Program.MainForm.CurrentProject.ProjectVersion); string progVersion = Convert.ToString(_versionHandler.CurrentVersion); VersionReader.CompareVersionResult versionCompare = VersionReader.CompareVersions(projVersion, progVersion); if (versionCompare == VersionReader.CompareVersionResult.VersionSame) { loadProjectBtn_Click(null, EventArgs.Empty); } else if (versionCompare == VersionReader.CompareVersionResult.VersionNew) { loadProjectBtn_Click(null, EventArgs.Empty); } else if (versionCompare == VersionReader.CompareVersionResult.VersionOld) { MessageBox.Show(translations.StartupForm_pathTextBox_TextChanged_ProjectVersionNewer); Application.Exit(); } } else { MessageBox.Show(Convert.ToString(translations.StartupForm_pathTextBox_TextChanged_InvalidESPrj)); Application.Exit(); } } }