Example #1
0
        private void ExtractFromSaveFile(string file)
        {
            ClearAll();
            isWorking(true);
            var savefile = file;
            var isXbox   = Path.GetFileName(file).ToLowerInvariant().Contains("xbox") || Path.GetFileName(file) == "band3";

            isWii = Path.GetFileName(file).ToLowerInvariant().Contains("wii");
            isPS3 = Path.GetFileName(file).ToLowerInvariant().Contains("ps3");
            Tools.CurrentFolder = Path.GetDirectoryName(file);
            UserSaveFile        = file;

            if (VariousFunctions.ReadFileType(file) == XboxFileType.STFS)
            {
                isXbox = true;
                isPS3  = false;
                isWii  = false;

                Log("Received save CON file, extracting save.dat file");
                var package = new STFSPackage(file);
                if (!package.ParseSuccess)
                {
                    isWorking(false);
                    package.CloseIO();
                    Log("Couldn't read that CON file, aborting");
                    Log("Ready");
                    return;
                }
                var xent = package.GetFile("save.dat");
                if (xent == null)
                {
                    isWorking(false);
                    package.CloseIO();
                    Log("Couldn't find save.dat in that CON file, aborting");
                    Log("Ready");
                    return;
                }
                var tempdat = EditorFolder + "\\temp.dat";
                Tools.DeleteFile(tempdat);
                if (!xent.ExtractToFile(tempdat))
                {
                    isWorking(false);
                    package.CloseIO();
                    Log("Couldn't extract save.dat from that CON file, aborting");
                    Log("Ready");
                    return;
                }
                savefile = tempdat;
                package.CloseIO();
            }
            Log("Received save file, extracting images...");

            ImageFolder = EditorFolder + Path.GetFileNameWithoutExtension(file) + "_extracted\\";
            Tools.DeleteFolder(ImageFolder, true);

            var success = false;

            if (isXbox)
            {
                success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file));
            }
            else if (isWii)
            {
                success = Tools.ExtractWiiSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file));
            }
            else if (isPS3)
            {
                success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file), true);
            }
            else
            {
                switch (MessageBox.Show("Click Yes if this is a *decrypted* PS3 save file\nClick No if this is a Wii save file\nXbox 360 users must use the 'band3' save file\nPress Cancel to go back",
                                        Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                case DialogResult.Yes:
                    isPS3   = true;
                    isWii   = false;
                    success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file), true);
                    break;

                case DialogResult.No:
                    isWii   = true;
                    isPS3   = false;
                    success = Tools.ExtractWiiSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file));
                    break;

                case DialogResult.Cancel:
                    Log("Extracting cancelled by user");
                    isWorking(false);
                    Log("Ready");
                    return;
                }
            }

            if (!success)
            {
                Log("Extracting from save game file failed");
                isWorking(false);
                Log("Ready");
                return;
            }
            Log("Extracted images from save file successfully");

            if (savefile != file) //i.e. extracted from con
            {
                Tools.DeleteFile(savefile);
            }

            lblFileName.Text = Path.GetFileName(file);
            lblConsole.Text  = isPS3 ? "Playstation 3" : (isWii ? "Wii" : "Xbox 360");
            ChangeImagePadding();
            LoadExtractedImages();
            exportAllImagesToolStripMenuItem.Enabled = true;
            closeFileToolStripMenuItem.Enabled       = true;

            txtBand.Enabled  = true;
            txtBand.Text     = !string.IsNullOrWhiteSpace(Tools.SaveFileBandName) ? Tools.SaveFileBandName : "Unknown";
            txtBand.ReadOnly = isWii;

            isWorking(false);
            Log("Ready");
        }