/// <summary> /// Loads every .ai file and parses it for use within this form /// </summary> protected void ParseTemplates() { // Clear nodesand Globals! treeView1.Nodes.Clear(); ObjectManager.ReleaseAll(); // OPen task form if it isnt open if (!TaskForm.IsOpen) { TaskForm.Show(this, "Parsing AI FIles", "Parsing AI Files", false); } // Load kit Templates TaskForm.UpdateStatus("Loading Kits, Please Wait..."); LoadKitTemplate(); // Load Vehicle templates TaskForm.UpdateStatus("Loading Vehicles, Please Wait..."); LoadTemplates("Vehicles"); // Load Weapon templates TaskForm.UpdateInstructionText("Lodding Weapons, Please Wait..."); LoadTemplates("Weapons"); TaskForm.CloseForm(); // Set desc DescLabel.Text = "Loaded Archive: " + ShrinkPath(Settings.Default.LastUsedZip, 95); // Enable action buttons SaveBtn.Enabled = true; RestoreBtn.Enabled = File.Exists(Settings.Default.LastUsedZip + ".original"); RefreshBtn.Enabled = true; }
private void SaveBtn_Click(object sender, EventArgs e) { string serverZip = Settings.Default.LastUsedZip; string appPath = Path.Combine(Application.StartupPath, "Temp"); // Show task form TaskForm.Show(this, "Saving Archive", "Saving Changes to Archive", false); // Get our AI files TaskForm.UpdateStatus("Fetching AI Files..."); IEnumerable <string> files = ( from x in Directory.GetFiles(appPath, "*.ai", SearchOption.AllDirectories) let dir = x.Remove(0, appPath.Length + 1) select dir ); // Save all AI files TaskForm.UpdateStatus("Saving AI file changes..."); foreach (TreeNode N in treeView1.Nodes) { SaveAiFiles(N); } // Create Backup! if (!File.Exists(serverZip + ".original")) { TaskForm.UpdateStatus("Creating Backup of server Archive..."); File.Copy(serverZip, serverZip + ".original"); RestoreBtn.Enabled = true; } // Remove readonly from zip FileInfo zipFile = new FileInfo(serverZip); zipFile.Attributes = FileAttributes.Normal; // Save files to zip using (ZipFile file = new ZipFile(serverZip)) { foreach (string pth in files) { TaskForm.UpdateStatus("Updating Entries..."); // Remove old entry file.RemoveEntry(pth); // Set file attributes to read only on the file, and add it to the zip ZipEntry t = file.AddEntry(pth, File.OpenRead(Path.Combine(appPath, pth))); t.Attributes = FileAttributes.ReadOnly; } file.Save(); } zipFile.Attributes = FileAttributes.ReadOnly; TaskForm.CloseForm(); }