/// <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 RefreshBtn_Click(object sender, EventArgs e) { TaskForm.Show(this, "Parsing AI FIles", "Parsing AI Files", false); tabControl1.Enabled = false; ClearTabValues(); ParseTemplates(); SelectedNode = null; }
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(); }
/// <summary> /// Event fired when the "Load Archive" button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewProfileBtn_Click(object sender, EventArgs e) { OpenFileDialog Dialog = new OpenFileDialog(); Dialog.FileName = "Objects_Server.zip"; Dialog.Filter = "Zip File|*.zip"; // Set the initial search directory if we found an install path via registry if (!String.IsNullOrWhiteSpace(Settings.Default.LastUsedPath)) { Dialog.InitialDirectory = Settings.Default.LastUsedPath; } // Show Dialog if (Dialog.ShowDialog() == DialogResult.OK) { // Save our last used directory string file = Dialog.FileName; Settings.Default.LastUsedPath = Path.GetDirectoryName(file); Settings.Default.LastUsedZip = file; Settings.Default.Save(); // Show our task form TaskForm.Show(this, "Loading Archive", "Extracting Archive", false); TaskForm.UpdateStatus("Removing old temp files..."); // Clear old temp data string targetDirectory = Path.Combine(Application.StartupPath, "Temp"); if (Directory.Exists(targetDirectory)) { Directory.Delete(targetDirectory, true); Thread.Sleep(250); } // Load zip TaskForm.UpdateStatus("Extracting Zip Contents..."); using (ZipFile Zip = ZipFile.Read(file)) { // Extract just the files we need ZipEntry[] Entries = Zip.Entries.Where( x => ( x.FileName.StartsWith("Vehicles", StringComparison.InvariantCultureIgnoreCase) || x.FileName.StartsWith("Weapons", StringComparison.InvariantCultureIgnoreCase) || x.FileName.StartsWith("Kits", StringComparison.InvariantCultureIgnoreCase) ) && x.FileName.EndsWith(".ai", StringComparison.InvariantCultureIgnoreCase) ).ToArray(); // Extract entries foreach (ZipEntry entry in Entries) { // Extract the entry entry.Extract(targetDirectory, ExtractExistingFileAction.Throw); // Get rid of read only attributes! FileInfo F = new FileInfo(Path.Combine(targetDirectory, entry.FileName)); F.Attributes = FileAttributes.Normal; } } // Prase the extracted ai files ParseTemplates(); } }