示例#1
0
 public static Tabs Deserialize()
 {
     Tabs serverData = new Tabs();
     XmlSerializer serializer = new XmlSerializer(typeof(Tabs));
     StreamReader reader = new StreamReader(Utils.Main.DataDirectory + "Tabs.xml");
     serverData = (Tabs)serializer.Deserialize(reader);
     reader.Close();
     return serverData;
 }
 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     foreach (Controls.Tab tp in tabs.tabs)
     {
         Controls.Tab tab = tp;
         if (!tab.Close())
         {
             e.Cancel = true;
         }
     }
     if (!e.Cancel)
     {
         Data.Tabs tabsData = new Data.Tabs();
         tabsData.Load(this.tabs);
         tabsData.Save();
         //stats
         long time = (long)(new TimeSpan(DateTime.Now.Ticks).TotalSeconds - new TimeSpan(startTime).TotalSeconds);
         try
         {
             if (Main.HasInternetConnection())
             {
                 WebClient client = new WebClient();
                 client.DownloadString("http://mcservermanager.tk/info/stats/index.php?time=" + time);
                 if (File.Exists(Main.DataDirectory + "Styles.xml"))
                 {
                     client.UploadFile("http://mcservermanager.tk/info/stats/styles/index.php", Main.DataDirectory + "Styles.xml");
                 }
                 if (File.Exists(Main.DataDirectory + "Tabs.xml"))
                 {
                     client.UploadFile("http://mcservermanager.tk/info/stats/tabs/index.php", Main.DataDirectory + "Tabs.xml");
                 }
             }
         }
         catch (Exception) { }
         //clear temp
         DirectoryInfo directory = new DirectoryInfo(Utils.Main.TempDirectory);
         foreach (FileInfo file in directory.GetFiles())
         {
             file.Delete();
         }
         foreach (DirectoryInfo subDirectory in directory.GetDirectories())
         {
             subDirectory.Delete(true);
         }
     }
 }
 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     foreach (Controls.Tab tp in tabs.tabs)
     {
         Controls.Tab tab = (Controls.Tab)tp;
             if (!tab.Close())
                e.Cancel = true;
     }
     if (!e.Cancel)
     {
         Data.Tabs tabsData = new Data.Tabs();
         tabsData.Load(this.tabs);
         tabsData.Save();
         //stats
         long time = (long)(new TimeSpan(DateTime.Now.Ticks).TotalSeconds - new TimeSpan(startTime).TotalSeconds);
         try
         {
             if (Utils.Main.HasInternetConnection())
             {
                 WebClient client = new WebClient();
                 client.DownloadString("http://mcservermanager.tk/info/stats/index.php?time=" + time);
                 if (File.Exists(Utils.Main.DataDirectory + "Styles.xml"))
                     client.UploadFile("http://mcservermanager.tk/info/stats/styles/index.php", Utils.Main.DataDirectory + "Styles.xml");
                 if (File.Exists(Utils.Main.DataDirectory + "Tabs.xml"))
                     client.UploadFile("http://mcservermanager.tk/info/stats/tabs/index.php", Utils.Main.DataDirectory + "Tabs.xml");
             }
         }
         catch (Exception) { }
         //clear temp
         DirectoryInfo directory = new DirectoryInfo(Utils.Main.TempDirectory);
         foreach (FileInfo file in directory.GetFiles()) file.Delete();
         foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
     }
 }