private void Save() { SoundPlayer Patience = new SoundPlayer(); Console.WriteLine(); FileInfo fi = new FileInfo(Filename); if (File.Exists(Filename) && fi.IsFileLocked()) { Console.WriteLine("The chosen file cannot be accessed. The file has not been modified, and your changes have not been saved."); goto SaveFailed; } if (Program.CanPlaySfx(Program.WaitSfx)) { Patience.SoundLocation = Program.WaitSfx; Patience.Load(); Patience.PlayLooping(); } if (CameraListBox.SelectedIndex != -1) { ((CameraPanelBase)MainSplitContainer.Panel2.Controls[0]).UnLoadCamera(Cameras[CameraListBox.SelectedIndex]); } if (Settings.Default.IsEnforceCompress) { AdvancedSave(); } if (File.Exists(Filename) && fi.IsFileLocked()) { Console.WriteLine("The chosen file cannot be accessed. The file has not been modified, and your changes have not been saved."); goto SaveFailed; } switch (fi.Extension) { case ".bcam": Console.WriteLine("Saving as a Binary Camera file:"); FileStream fs = new FileStream(Filename, FileMode.Create); Cameras.Save(fs); fs.Close(); break; case ".arc": case ".rarc": if (!File.Exists(Filename)) { MessageBox.Show("The output archive does not exist. Your changes have not been saved."); goto SaveFailed; } Console.WriteLine("Loading the target Archive:"); RARC Archive = YAZ0.Check(Filename) ? new RARC(YAZ0.DecompressToMemoryStream(Filename)) : new RARC(Filename); Console.WriteLine("Archive Loaded. Looking for the .bcam to replace..."); string FinalPath = new string[] { Archive.GetItemKeyFromNoCase("Camera/CameraParam.bcam"), Archive.GetItemKeyFromNoCase("ActorInfo/CameraParam.bcam") }.FirstOrDefault(s => !string.IsNullOrEmpty(s)); if (FinalPath is null) { Console.WriteLine("Error finding a bcam"); DialogResult dr = MessageBox.Show("The archive has no .bcam to replace.\nWould you like to create one?", "Missing .bcam", MessageBoxButtons.YesNo, MessageBoxIcon.Question); Console.WriteLine($"MessageBox Response: {dr.ToString()}"); if (dr != DialogResult.Yes) { Console.WriteLine("The chosen file has not been modified, and your changes have not been saved."); goto SaveFailed; } FinalPath = "Camera/CameraParam.bcam"; } Console.WriteLine(FinalPath is null ? "Injecting..." : ".bcam found. Saving..."); MemoryStream ms = new MemoryStream(); Cameras.Save(ms); Archive[FinalPath] = new RARC.File(((RARC.File)Archive[FinalPath]).Name, ms); Console.WriteLine(".bcam saved into the archive."); Console.WriteLine("Saving the archive..."); Archive.Save(Filename); if (Settings.Default.IsUseYAZ0) { Stopwatch Watch = new Stopwatch(); long UncompressedFilesize = File.ReadAllBytes(Filename).Length; double ETA = UncompressedFilesize * Settings.Default.ElapsedTimeStrong; Watch.Start(); Yaz0BackgroundWorker.RunWorkerAsync(Filename); EnabledContents(this, false); while (Yaz0BackgroundWorker.IsBusy) { Console.Write($"\rYaz0 Encoding: ({Watch.Elapsed.ToString("mm\\:ss\\.fff")} Elapsed, {TimeSpan.FromMilliseconds(ETA).ToString("mm\\:ss\\.fff")} Estimated)"); Application.DoEvents(); } Watch.Stop(); Settings.Default.ElapsedTimeStrong = (double)Watch.ElapsedMilliseconds / (double)UncompressedFilesize; Console.WriteLine("\nYaz0 Encoding Complete!"); EnabledContents(this, true); } break; } Console.WriteLine("Save Complete!"); Console.WriteLine("Current time of Save: " + DateTime.Now.ToString("h:mm tt")); Program.IsUnsavedChanges = false; Console.WriteLine(); Patience.Stop(); if (Program.CanPlaySfx(Program.SuccessSfx)) { Patience.SoundLocation = Program.SuccessSfx; Patience.Load(); Patience.Play(); } return; SaveFailed: Patience.Stop(); if (Program.CanPlaySfx(Program.FailureSfx)) { Patience.SoundLocation = Program.FailureSfx; Patience.Load(); Patience.Play(); } return; }
public void Open(string file) { CameraListBox.SelectedIndex = -1; Filename = file; SoundPlayer Patience = new SoundPlayer(); if (File.Exists(Filename) && new FileInfo(file).IsFileLocked()) { Console.WriteLine("The chosen file cannot be accessed. The file has not been modified, and your changes have not been saved."); goto OpenFailed; } if (Program.CanPlaySfx(Program.WaitSfx)) { Patience.SoundLocation = Program.WaitSfx; Patience.Load(); Patience.PlayLooping(); } switch (new FileInfo(file).Extension) { case ".bcam": Console.WriteLine("Loading as a Binary Camera file:"); FileStream fs = new FileStream(file, FileMode.Open); Cameras = new BCAM(fs); fs.Close(); Console.WriteLine("Load Complete!"); break; case ".arc": case ".rarc": Console.WriteLine("Loading as an Archive:"); RARC Archive = YAZ0.Check(file) ? new RARC(new MemoryStream(YAZ0.Decompress(File.ReadAllBytes(file)))) : new RARC(file); Console.WriteLine("Archive Loaded. Looking for the .bcam..."); string CameraParamPath = Archive.GetItemKeyFromNoCase("Camera/CameraParam.bcam"); if (CameraParamPath == null) { CameraParamPath = Archive.GetItemKeyFromNoCase("ActorInfo/CameraParam.bcam"); if (CameraParamPath == null) { Console.WriteLine("Load Failed! No BCAM was found inside the archive!\n(Maybe it was in the wrong place?)"); goto OpenFailed; } } Console.WriteLine(".bcam found."); Cameras = new BCAM(new MemoryStream(((RARC.File)Archive[CameraParamPath]).FileData)); Console.WriteLine("Load Complete!"); break; } Console.WriteLine(); Console.WriteLine("Writing the Camera List:"); CameraListBox.Enabled = false; CameraListBox.Items.Clear(); for (int i = 0; i < Cameras.EntryCount; i++) { CameraListBox.Items.Add(Cameras[i].GetTranslatedName()); Console.Write($"\r{Math.Min((int)(((float)(i + 1) / (float)CameraListBox.Items.Count) * 100), 100)}% "); } Console.WriteLine("Complete"); if (Cameras.EntryCount > 0) { CameraListBox.SelectedIndex = 0; } CameraListBox.Enabled = true; SaveToolStripMenuItem.Enabled = true; SaveAsToolStripMenuItem.Enabled = true; ExportPresetToolStripMenuItem.Enabled = true; Program.IsUnsavedChanges = false; Patience.Stop(); if (Program.CanPlaySfx(Program.SuccessSfx)) { Patience.SoundLocation = Program.SuccessSfx; Patience.Load(); Patience.Play(); } return; OpenFailed: Patience.Stop(); if (Program.CanPlaySfx(Program.FailureSfx)) { Patience.SoundLocation = Program.FailureSfx; Patience.Load(); Patience.Play(); } }