Example #1
0
        static void Main(string[] OpenWith)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (Settings.Default.IsNeedUpgrade)
            {
                Settings.Default.Upgrade();
                Settings.Default.IsNeedUpgrade = false;
                Settings.Default.Save();
            }

            if (OpenWith.Length > 1)
            {
                if ((OpenWith[0].Equals("--script") || OpenWith[0].Equals("-ss")))
                {
                    AttachConsole(ATTACH_PARENT_PROCESS);
                    List <string> Parameters = new List <string>();
                    for (int i = 2; i < OpenWith.Length; i++)
                    {
                        Parameters.Add(OpenWith[i]);
                    }
                    RunScript(OpenWith[1], Parameters.ToArray());
                    return;
                }
                if ((OpenWith[0].Equals("--pack") || OpenWith[0].Equals("-p")) && File.GetAttributes(OpenWith[OpenWith.Length - 1]) == FileAttributes.Directory)
                {
                    RARC Archive = new RARC();
                    Archive.Import(OpenWith[OpenWith.Length - 1]);
                    DirectoryInfo di     = new DirectoryInfo(OpenWith[OpenWith.Length - 1]);
                    string        output = Path.Combine(di.Parent.FullName, di.Name + ".arc");
                    Archive.Save(output);
                    if (OpenWith.Any(S => S.Equals("--yaz0") || S.Equals("-yz")))
                    {
                        YAZ0.Compress(output, OpenWith.Any(S => S.Equals("--fast") || S.Equals("-f")));
                    }
                    else if (OpenWith.Any(S => S.Equals("--yay0") || S.Equals("-yy")))
                    {
                        YAY0.Compress(output);
                    }
                    return;
                }
                else if ((OpenWith[0].Equals("--unpack") || OpenWith[0].Equals("-u")) && File.GetAttributes(OpenWith[OpenWith.Length - 1]) == FileAttributes.Normal)
                {
                    bool   IsYaz0  = YAZ0.Check(OpenWith[OpenWith.Length - 1]);
                    bool   IsYay0  = YAY0.Check(OpenWith[OpenWith.Length - 1]);
                    RARC   Archive = IsYaz0 ? new RARC(YAZ0.DecompressToMemoryStream(OpenWith[OpenWith.Length - 1]), OpenWith[OpenWith.Length - 1]) : (IsYay0 ? new RARC(YAY0.DecompressToMemoryStream(OpenWith[OpenWith.Length - 1]), OpenWith[OpenWith.Length - 1]) : new RARC(OpenWith[OpenWith.Length - 1]));
                    string output  = new FileInfo(Archive.FileName).Directory.FullName;
                    Archive.Export(output, OpenWith.Any(S => S.Equals("--overwrite") || S.Equals("-o")));
                    return;
                }

                for (int i = 0; i < OpenWith.Length; i++)
                {
                    if ((OpenWith[i].Equals("--lang") || OpenWith[i].Equals("-l")) && OpenWith.Length == i + 2)
                    {
                        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(OpenWith[i + 1]);
                    }
                }
            }
            //Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ja");

            if (OpenWith.Length == 0)
            {
                OpenWith = new string[1] {
                    null
                }
            }
            ;
            Application.Run(new MainForm(OpenWith[0]));
            return;
        }
Example #2
0
        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;
        }