private void LoadCGM(string customCGM)
        {
            if (!String.IsNullOrEmpty(customCGM))
            {
                // Unpack CGM file (7z file format)
                var unpackedFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(customCGM));

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

                ExternalApps.ExtractZip(customCGM, unpackedFolder);

                var errorMessage = string.Format("Template {0} can't be loaded, maybe doesn't exists or is corrupted.", customCGM);
                if (!Directory.Exists(unpackedFolder))
                {
                    MessageBox.Show(errorMessage, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Setup inlay pre-definition
                Frets24Checkbox.Checked = ColoredCheckbox.Checked = chkFlipX.Checked = chkFlipY.Checked = false;

                // Open the setup.smb INI file
                Configuration iniConfig = Configuration.LoadFromFile(Path.Combine(unpackedFolder, "setup.smb"));

                // switch to new sharpconfig.dll ini file format with [General] section
                // allow for backward compatibility with old *.cgm files
                try
                {
                    Author    = iniConfig["General"]["author"].Value;
                    InlayName = iniConfig["General"]["inlayname"].Value;
                    Frets24   = iniConfig["General"]["24frets"].GetValue <bool>();
                    Colored   = iniConfig["General"]["colored"].GetValue <bool>();
                }
                catch
                {
                    Author    = iniConfig["Setup"]["creatorname"].Value;
                    InlayName = iniConfig["Setup"]["guitarname"].Value;
                    try
                    {
                        // skip exception for templates created with old v2.0.0.71b
                        Frets24 = iniConfig["Setup"]["24frets"].GetValue <bool>();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception: Incomplete INI file - " + e.Message);
                    }
                    Colored = iniConfig["Setup"]["coloredinlay"].GetValue <bool>();
                }

                // Convert the dds files to png
                var iconFile = Path.Combine(unpackedFolder, "icon.dds");
                ExternalApps.Dds2Png(iconFile);
                var inlayFile = Path.Combine(unpackedFolder, "inlay.dds");
                ExternalApps.Dds2Png(inlayFile);

                if (!File.Exists(iconFile) || !File.Exists(inlayFile))
                {
                    MessageBox.Show(errorMessage, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Load png into picBoxes and save paths
                picIcon.ImageLocation  = IconFile = Path.ChangeExtension(iconFile, ".png");
                picInlay.ImageLocation = InlayFile = Path.ChangeExtension(inlayFile, ".png");
            }
        }
Exemplo n.º 2
0
        private void LoadImages(string cisPath)
        {
            // init image array and clear pics
            InitImageArray();
            InitImagePics();
            if (!File.Exists(cisPath))
            {
                return;
            }

            // background worker does not work with this method because it updates the
            // form/controls, so using alternate method to report progress
            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 = 10;

            ProcessStarted(progress, "Loading images from Intro Screens Template file ...");

            // create temp folder for unzipping *.cis file
            var tmpUnzipDir = Path.Combine(tmpWorkDir, "cis_unzip");

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

            var srcPath  = cisPath;
            var destPath = tmpUnzipDir;

            ExternalApps.ExtractZip(srcPath, destPath);

            // Open the setup.smb INI file
            Configuration iniConfig = Configuration.LoadFromFile(Path.Combine(tmpUnzipDir, "setup.smb"));

            txtAuthor.Text       = iniConfig["General"]["author"].Value;
            txtSeqName.Text      = iniConfig["General"]["seqname"].Value;
            txtAuthor.ForeColor  = Color.Black;
            txtSeqName.ForeColor = Color.Black;

            // Convert the dds files to png
            IEnumerable <string> ismList = Directory.EnumerateFiles(tmpUnzipDir, "*.dds");

            foreach (string imagePath in ismList)
            {
                progress += step;
                ProcessStarted(progress, "Converting images to PNG files ... " + progress);

                ExternalApps.Dds2Png(imagePath);
                for (int i = 0; i < imageArray.GetUpperBound(0); i++)
                {
                    if (Path.GetFileName(imageArray[i, 2]) == Path.GetFileName(imagePath))
                    {
                        // Load user image paths and png into picBoxes
                        imageArray[i, 3] = Path.ChangeExtension(imagePath, ".png");
                        switch (Path.GetFileName(imagePath))
                        {
                        case "introsequence_i15.dds":
                            picBackground.ImageLocation = imageArray[i, 3];
                            lblBackground.Visible       = false;
                            break;

                        case "introsequence_i11.dds":
                            picCredits.ImageLocation = imageArray[i, 3];
                            lblCredits.Visible       = false;
                            break;

                        case "ubisoft_logo.png.dds":
                            picUbi.ImageLocation = imageArray[i, 3];
                            lblUbi.Visible       = false;
                            break;

                        case "gamebryo_logo.png.dds":
                            picLightspeed.ImageLocation = imageArray[i, 3];
                            lblLightspeed.Visible       = false;
                            break;

                        case "intro_studio_logos.png.dds":
                            picPedals.ImageLocation = imageArray[i, 3];
                            lblPedals.Visible       = false;
                            break;

                        case "rocksmith_2014_logo.dds":
                            picTitle.ImageLocation = imageArray[i, 3];
                            lblTitle.Visible       = false;
                            break;
                        }
                    }
                }
            }
            ProcessCompleted(null, null);
        }