Пример #1
0
 /// <summary>
 /// Change SA:MP version
 /// </summary>
 /// <param name="version">Version</param>
 /// <param name="useInstaller">Use installer</param>
 public static void ChangeSAMPVersion(SAMPVersion version, bool useInstaller)
 {
     if (version != null)
     {
         DownloadProgressForm dpf = new DownloadProgressForm(useInstaller ? version.InstallationURI : version.ZipURI, useInstaller ? "install.exe" : "client.zip");
         if (dpf.ShowDialog() == DialogResult.OK)
         {
             SAMPProvider.ResetVersionCache();
             try
             {
                 if (File.Exists(dpf.Path))
                 {
                     if (useInstaller)
                     {
                         Process.Start(dpf.Path);
                         Application.Exit();
                     }
                     else
                     {
                         using (ZipArchive archive = ZipFile.Open(dpf.Path, ZipArchiveMode.Read))
                         {
                             foreach (ZipArchiveEntry entry in archive.Entries)
                             {
                                 string path = ExeDir + "\\" + entry.FullName.Replace('/', '\\');
                                 try
                                 {
                                     using (Stream stream = entry.Open())
                                     {
                                         using (FileStream file_stream = new FileStream(path, FileMode.Create))
                                         {
                                             int b = -1;
                                             while ((b = stream.ReadByte()) != -1)
                                             {
                                                 file_stream.WriteByte((byte)b);
                                             }
                                         }
                                     }
                                 }
                                 catch (Exception e)
                                 {
                                     Console.Error.WriteLine(e.Message);
                                 }
                             }
                         }
                     }
                 }
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Reset version cache
 /// </summary>
 public static void ResetVersionCache()
 {
     versionRequired = true;
     currentVersion  = null;
 }