Esempio n. 1
0
        private void SaveImages(object sender, DoWorkEventArgs e)
        {
            // method using Background Worker to report progress
            var       savePath = e.Argument as string;
            const int numSteps = 7; // max number of times progress change is reported
            var       step     = (int)Math.Round(1.0 / (numSteps + 2) * 100, 0);
            var       progress = 0;

            // Create temp folder for zipping files
            var tmpZipDir = Path.Combine(tmpWorkDir, "cis_zip");

            if (Directory.Exists(tmpZipDir))
            {
                DirectoryExtension.SafeDelete(tmpZipDir, true);
            }
            Directory.CreateDirectory(tmpZipDir);

            // convert user png images to dds images
            for (int i = 0; i < imageArray.GetUpperBound(0); i++)
            {
                progress += step;
                bwSaveImages.ReportProgress(progress, "Converting user PNG images ... " + i.ToString());

                if (imageArray[i, 3] != null) // user has specified a replacement image
                {
                    // CRITICAL PATH AND ARGS
                    var srcPath  = imageArray[i, 3];
                    var destPath = Path.Combine(tmpZipDir, Path.GetFileName(imageArray[i, 2]));
                    ExternalApps.Png2Dds(srcPath, destPath, ImageHandler.Size2IntX(imageArray[i, 1]), ImageHandler.Size2IntY(imageArray[i, 1]));
                }
            }
            progress += step;
            bwSaveImages.ReportProgress(progress, "Saving Intro Screens Template file ... ");

            // Write ini file setup.smb
            var           iniFile = Path.Combine(tmpZipDir, "setup.smb");
            Configuration iniCFG  = new Configuration();

            iniCFG["General"].Add(new Setting("author", String.IsNullOrEmpty(txtAuthor.Text) ? "CSC" : txtAuthor.Text));
            iniCFG["General"].Add(new Setting("seqname", String.IsNullOrEmpty(txtSeqName.Text) ? "SystemSaved" : txtSeqName.Text));
            iniCFG["General"].Add(new Setting("cscvers", ToolkitVersion.version));
            iniCFG["General"].Add(new Setting("modified", DateTime.Now.ToShortDateString()));
            iniCFG.Save(iniFile);

            // Zip intro sequence *.cis file
            ExternalApps.InjectZip(tmpZipDir, savePath, false, true);
        }
        private void saveCGMButton_Click(object sender, EventArgs e)
        {
            var saveFile = String.Empty;

            using (var sfd = new SaveFileDialog())
            {
                sfd.Title            = "Select a location to store your CGM file";
                sfd.Filter           = "CGM file (*.cgm)|*.cgm";
                sfd.InitialDirectory = Path.Combine(workDir, "cgm");
                sfd.FileName         = (InlayName.GetValidInlayName(Frets24)) + "_" + StringExtensions.GetValidAcronym(Author) + ".cgm".GetValidFileName();

                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                saveFile = sfd.FileName;
            }

            // Create workDir folder
            var tmpWorkDir = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(saveFile));

            if (Directory.Exists(tmpWorkDir))
            {
                IOExtension.DeleteDirectory(tmpWorkDir);
            }

            if (!Directory.Exists(tmpWorkDir))
            {
                Directory.CreateDirectory(tmpWorkDir);
            }

            // Convert PNG to DDS
            ExternalApps.Png2Dds(IconFile, Path.Combine(tmpWorkDir, "icon.dds"), 512, 512);
            ExternalApps.Png2Dds(InlayFile, Path.Combine(tmpWorkDir, "inlay.dds"), 1024, 512);

            // Create setup.smb
            var           iniFile = Path.Combine(tmpWorkDir, "setup.smb");
            Configuration iniCFG  = new Configuration();

            // sharpconfig.dll automatically creates a new [General] section in the INI file
            iniCFG["General"].Add(new Setting("author", String.IsNullOrEmpty(Author) ? "CSC" : Author));
            iniCFG["General"].Add(new Setting("inlayname", String.IsNullOrEmpty(InlayName) ? "null" : InlayName));
            iniCFG["General"].Add(new Setting("24frets", Convert.ToString(Convert.ToInt32(Frets24))));
            iniCFG["General"].Add(new Setting("colored", Convert.ToString(Convert.ToInt32(Colored))));
            iniCFG["General"].Add(new Setting("cscvers", ToolkitVersion.RSTKGuiVersion.Replace("-00000000", "")));
            iniCFG["General"].Add(new Setting("modified", DateTime.Now.ToShortDateString()));
            iniCFG.Save(iniFile);

            // Pack file into a .cgm file (7zip file format)
            ExternalApps.InjectZip(tmpWorkDir, saveFile, false, true);

            // Delete temp work dir
            if (Directory.Exists(tmpWorkDir))
            {
                IOExtension.DeleteDirectory(tmpWorkDir);
            }

            if (MessageBox.Show("Inlay template was saved." + Environment.NewLine + "Would you like to open the folder?", MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                Process.Start(Path.GetDirectoryName(saveFile));
            }

            if (Path.GetDirectoryName(saveFile) == Path.Combine(workDir, "cgm"))
            {
                inlayTemplateCombo.Items.Add(Path.GetFileNameWithoutExtension(saveFile));
                inlayTemplateCombo.SelectedIndex = (inlayTemplateCombo.Items.Count - 1);
            }
        }
Esempio n. 3
0
        private void UpdateCache()
        {
            // unpack cache.psarc
            const int numSteps = 8; // max number of times ReportProgress will be called
            var       step     = (int)Math.Round(1.0 / (numSteps + 2) * 100, 0);
            int       progress = 0;

            progress += step;
            ProcessStarted(progress, "Unpacking cache file ... ");

            var srcPath  = Path.Combine(rsDir, "cache.psarc");
            var destPath = Path.Combine(rsDir, "cache.psarc.org");

            // backup the original cache.psarc and never overwrite it
            if (!File.Exists(destPath))
            {
                File.Copy(srcPath, destPath, false);
            }

            var tmpCisDir = Path.Combine(tmpWorkDir, "cis_cache");

            if (Directory.Exists(tmpCisDir))
            {
                DirectoryExtension.SafeDelete(tmpCisDir, true);
            }
            // CRITCAL PATH
            Directory.CreateDirectory(Path.Combine(tmpCisDir, "cache4\\gfxassets\\views"));
            destPath = tmpCisDir;
            Packer.Unpack(srcPath, destPath);
            // ExternalApps.UnpackPsarc(srcPath, destPath, DLCInlayCreator.GlobalTitlePlatform);

            // convert user png images to dds images
            for (int i = 0; i < 5; i++)
            {
                progress += step;
                ProcessStarted(progress, "Convertng user PNG images ...");

                if (imageArray[i, 3] != null) // user has specified a replacement image
                {
                    // CRITICAL PATH AND ARGS
                    srcPath  = imageArray[i, 3];
                    destPath = Path.Combine(tmpCisDir, "cache4\\gfxassets\\views", Path.GetFileName(imageArray[i, 2]));
                    ExternalApps.Png2Dds(srcPath, destPath, ImageHandler.Size2IntX(imageArray[i, 1]), ImageHandler.Size2IntY(imageArray[i, 1]));
                }
            }

            // update user images to zip file
            progress += step;
            ProcessStarted(progress, "Injecting user images ...");
            // SUPER CRITICAL PATH AND ARGS
            var rootDir = string.Format("cache_{0}", DLCInlayCreator.GlobalTitlePlatform);

            srcPath  = Path.Combine(tmpCisDir, "cache4\\gfxassets");
            destPath = Path.Combine(tmpCisDir, rootDir, "cache4.7z");
            ExternalApps.InjectZip(srcPath, destPath, true);

            // repack cache.psarc
            progress += step;
            ProcessStarted(progress, "Repacking cache file ...");
            srcPath  = Path.Combine(tmpCisDir, rootDir);
            destPath = Path.Combine(rsDir, "cache.psarc");
            Packer.Pack(srcPath, destPath);
            // ExternalApps.RepackPsarc(srcPath, destPath, DLCInlayCreator.GlobalTitlePlatform);

            ProcessCompleted(null, null);
        }