示例#1
0
        public static void Load(string Filename, bool CorruptCloud)
        {
            if (Filename == null)
            {
                OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
                OpenFileDialog1.DefaultExt       = "sks";
                OpenFileDialog1.Title            = "Open Stockpile File";
                OpenFileDialog1.Filter           = "SKS files|*.sks";
                OpenFileDialog1.RestoreDirectory = true;
                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Filename = OpenFileDialog1.FileName.ToString();
                }
                else
                {
                    return;
                }
            }

            if (!File.Exists(Filename))
            {
                MessageBox.Show("The Stockpile file wasn't found");
                return;
            }


            //clean temp folder
            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP"))
            {
                File.Delete(file);
            }


            //7z extract part

            string[] stringargs = { "-x", Filename, RTC_Core.rtcDir + "\\TEMP\\" };

            FastZipProgram.Exec(stringargs);

            if (!File.Exists(RTC_Core.rtcDir + "\\TEMP\\master.sk"))
            {
                MessageBox.Show("The file could not be read properly");
                return;
            }



            //stockpile part
            FileStream      FS;
            BinaryFormatter bformatter = new BinaryFormatter();

            Stockpile sks;

            bformatter = new BinaryFormatter();

            try
            {
                FS  = File.Open(RTC_Core.rtcDir + "\\TEMP\\master.sk", FileMode.OpenOrCreate);
                sks = (Stockpile)bformatter.Deserialize(FS);
                FS.Close();
            }
            catch
            {
                MessageBox.Show("The Stockpile file could not be loaded");
                return;
            }

            RTC_Core.currentStockpile = sks;

            // repopulating savestates out of temp folder
            foreach (StashKey key in sks.stashkeys)
            {
                string statefilename = key.GameName + "." + key.ParentKey + ".timejump.State";                 // get savestate name

                if (!File.Exists(RTC_Core.bizhawkDir + "\\" + key.GameSystem + "\\State\\" + statefilename))
                {
                    File.Copy(RTC_Core.rtcDir + "\\TEMP\\" + statefilename, RTC_Core.bizhawkDir + "\\" + key.GameSystem + "\\State\\" + statefilename);                     // copy savestates to temp folder
                }
            }


            for (int i = 0; i < sks.stashkeys.Count; i++)
            {
                sks.stashkeys[i].RomFile = RTC_Core.rtcDir + "\\TEMP\\" + sks.stashkeys[i].RomFile;
            }


            //fill list controls
            RTC_Core.ghForm.lbStockpile.Items.Clear();
            RTC_Core.spForm.lbStockpile.Items.Clear();

            foreach (StashKey key in sks.stashkeys)
            {
                RTC_Core.ghForm.lbStockpile.Items.Add(key);
                RTC_Core.spForm.lbStockpile.Items.Add(key);
            }


            RTC_Core.ghForm.btnSaveStockpile.Enabled   = true;
            RTC_Core.ghForm.btnSaveStockpile.BackColor = Color.Tomato;
            sks.Filename = Filename;

            if (sks.RtcVersion != RTC_Core.RtcVersion)
            {
                if (sks.RtcVersion == null)
                {
                    MessageBox.Show("WARNING: You have loaded a pre-0.77 stockpile using RTC " + RTC_Core.RtcVersion + "\n Items might not appear identical to how they when they were created.");
                }
                else
                {
                    MessageBox.Show("WARNING: You have loaded a stockpile created with RTC " + sks.RtcVersion + " using RTC " + RTC_Core.RtcVersion + "\n Items might not appear identical to how they when they were created.");
                }
            }
        }
示例#2
0
        public static void Import(string Filename, bool CorruptCloud)
        {
            //clean temp folder
            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP3"))
            {
                File.Delete(file);
            }

            if (Filename == null)
            {
                OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
                OpenFileDialog1.DefaultExt       = "sks";
                OpenFileDialog1.Title            = "Open Stockpile File";
                OpenFileDialog1.Filter           = "SKS files|*.sks";
                OpenFileDialog1.RestoreDirectory = true;
                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Filename = OpenFileDialog1.FileName.ToString();
                }
                else
                {
                    return;
                }
            }

            if (!File.Exists(Filename))
            {
                MessageBox.Show("The Stockpile file wasn't found");
                return;
            }

            //7z extract part

            string[] stringargs = { "-x", Filename, RTC_Core.rtcDir + "\\TEMP3\\" };

            FastZipProgram.Exec(stringargs);

            if (!File.Exists(RTC_Core.rtcDir + "\\TEMP3\\master.sk"))
            {
                MessageBox.Show("The file could not be read properly");
                return;
            }



            //stockpile part
            FileStream      FS;
            BinaryFormatter bformatter = new BinaryFormatter();

            Stockpile sks;

            bformatter = new BinaryFormatter();

            try
            {
                FS  = File.Open(RTC_Core.rtcDir + "\\TEMP3\\master.sk", FileMode.OpenOrCreate);
                sks = (Stockpile)bformatter.Deserialize(FS);
                FS.Close();
            }
            catch
            {
                MessageBox.Show("The Stockpile file could not be loaded");
                return;
            }


            // repopulating savestates out of temp folder
            foreach (StashKey key in sks.stashkeys)
            {
                string statefilename = key.GameName + "." + key.ParentKey + ".timejump.State"; // get savestate name

                if (!File.Exists(RTC_Core.bizhawkDir + "\\" + key.GameSystem + "\\State\\" + statefilename))
                {
                    File.Copy(RTC_Core.rtcDir + "\\TEMP3\\" + statefilename, RTC_Core.bizhawkDir + "\\" + key.GameSystem + "\\State\\" + statefilename); // copy savestates to temp folder
                }
            }

            for (int i = 0; i < sks.stashkeys.Count; i++)
            {
                sks.stashkeys[i].RomFile = RTC_Core.rtcDir + "\\TEMP\\" + sks.stashkeys[i].RomFile;
            }

            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP3\\"))
            {
                if (!file.Contains(".sk") && !file.Contains(".timejump.State"))
                {
                    try
                    {
                        File.Copy(file, RTC_Core.rtcDir + "\\TEMP\\" + file.Substring(file.LastIndexOf('\\'), file.Length - file.LastIndexOf('\\'))); // copy roms to temp
                    }
                    catch {}
                }
            }

            //fill list controls

            foreach (StashKey key in sks.stashkeys)
            {
                RTC_Core.ghForm.lbStockpile.Items.Add(key);
            }
        }
示例#3
0
        public static void Save(Stockpile sks, bool IsQuickSave)
        {
            if (sks.stashkeys.Count == 0)
            {
                MessageBox.Show("Can't save because the Current Stockpile is empty");
                return;
            }

            if (!IsQuickSave)
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.DefaultExt       = "sks";
                saveFileDialog1.Title            = "Save Stockpile File";
                saveFileDialog1.Filter           = "SKS files|*.sks";
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    sks.Filename      = saveFileDialog1.FileName;
                    sks.ShortFilename = sks.Filename.Substring(sks.Filename.LastIndexOf("\\") + 1, sks.Filename.Length - (sks.Filename.LastIndexOf("\\") + 1));
                }
                else
                {
                    return;
                }
            }
            else
            {
                sks.Filename      = RTC_Core.currentStockpile.Filename;
                sks.ShortFilename = RTC_Core.currentStockpile.ShortFilename;
            }

            //Watermarking RTC Version
            sks.RtcVersion = RTC_Core.RtcVersion;

            FileStream      FS;
            BinaryFormatter bformatter = new BinaryFormatter();

            List <string> AllRoms = new List <string>();

            //populating Allroms array
            foreach (StashKey key in sks.stashkeys)
            {
                if (!AllRoms.Contains(key.RomFile))
                {
                    AllRoms.Add(key.RomFile);

                    if (key.RomFile.ToUpper().Contains(".CUE"))
                    {
                        AllRoms.Add(key.RomFile.Substring(0, key.RomFile.Length - 4) + ".bin");
                    }
                }
            }

            //clean temp2 folder
            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP2"))
            {
                File.Delete(file);
            }


            //populating temp2 folder with roms
            for (int i = 0; i < AllRoms.Count; i++)
            {
                string rom             = AllRoms[i];
                string romTempfilename = RTC_Core.rtcDir + "\\TEMP2\\" + (rom.Substring(rom.LastIndexOf("\\") + 1, rom.Length - (rom.LastIndexOf("\\") + 1)));


                if (File.Exists(romTempfilename))
                {
                    File.Delete(romTempfilename);
                    File.Copy(rom, romTempfilename);
                }
                else
                {
                    File.Copy(rom, romTempfilename);
                }
            }

            //clean temp folder
            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP"))
            {
                File.Delete(file);
            }

            //sending back filtered files from temp2 folder to temp
            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP2"))
            {
                File.Move(file, RTC_Core.rtcDir + "\\TEMP\\" + (file.Substring(file.LastIndexOf("\\") + 1, file.Length - (file.LastIndexOf("\\") + 1))));
            }

            //clean temp2 folder again
            foreach (string file in Directory.GetFiles(RTC_Core.rtcDir + "\\TEMP2"))
            {
                File.Delete(file);
            }

            foreach (StashKey key in sks.stashkeys)
            {
                string statefilename = key.GameName + "." + key.ParentKey + ".timejump.State"; // get savestate name

                if (!File.Exists(RTC_Core.rtcDir + "\\TEMP\\" + statefilename))
                {
                    File.Copy(RTC_Core.bizhawkDir + "\\" + key.GameSystem + "\\State\\" + statefilename, RTC_Core.rtcDir + "\\TEMP\\" + statefilename); // copy savestates to temp folder
                }
            }


            for (int i = 0; i < sks.stashkeys.Count; i++) //changes RomFile to short filename
            {
                sks.stashkeys[i].RomFile = sks.stashkeys[i].RomFile.Substring(sks.stashkeys[i].RomFile.LastIndexOf("\\") + 1, sks.stashkeys[i].RomFile.Length - (sks.stashkeys[i].RomFile.LastIndexOf("\\") + 1));
            }


            //creater master.sk to temp folder from stockpile object
            FS = File.Open(RTC_Core.rtcDir + "\\TEMP\\master.sk", FileMode.OpenOrCreate);
            bformatter.Serialize(FS, sks);
            FS.Close();


            //7z the temp folder to destination filename
            string[] stringargs = { "-c", sks.Filename, RTC_Core.rtcDir + "\\TEMP\\" };
            FastZipProgram.Exec(stringargs);


            //Imagine how long would it be with isos in that shit
            //Load(sks.Filename, true); //Reload file after for test and clean
        }