Example #1
0
        public void LoadImages(object sender, EventArgs e)
        {
            if (sender is BackgroundWorker)
            {
                worker = sender as BackgroundWorker;
            }
            else
            {
                worker = null;
            }

            List <string> scriptFiles = new List <string>();
            string        filter      = ".png.yaml";
            int           counter     = 0; // used to add a number to each image name, just in case disambiguation is required

            GenerateFileListFiltered(Path.Combine(ProjectFolder.GetRootDir(), ProjectFolder.buildScriptsDir), scriptFiles, filter);

            foreach (var script in scriptFiles)
            {
                GIMBuildObject buildInstructions = new GIMBuildObject();
                buildInstructions.DeserializeFromDisk(script);

                string pngFileLocation    = Path.Combine(ProjectFolder.GetRootDir(), buildInstructions.originalFileLocation);
                string targetFileLocation = Path.Combine(ProjectFolder.GetRootDir(), buildInstructions.targetFileLocation);

                counter++;

                if (worker != null)
                {
                    double progress = ((double)counter / (double)scriptFiles.Count) * 100;

                    worker.ReportProgress((int)progress);
                }

                if (worker != null)
                {
                    if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                    {
                        MessageBox.Show("Load images cancelled");
                        return;
                    }
                }

                string checksum;

                try
                {
                    FileStream   fs = new FileStream(pngFileLocation, FileMode.Open);
                    BinaryReader br = new BinaryReader(fs);

                    byte[] imageData = br.ReadBytes((int)br.BaseStream.Length);
                    checksum = Checksums.GetMD5(imageData);

                    br.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    continue; // this is primarily here to catch the odd "file that is supposed to exist in build script does not exist in image dir" problem. again, it is ideally something we will write to a log file at some point. user needs to be notified in some way.
                }

                if (checksum == buildInstructions.checksumValue)
                {
                    continue;
                }

                if (!ImageHandler.ConvertImage(pngFileLocation, targetFileLocation))
                {
                    continue;
                }
            }

            MessageBox.Show("Images loaded!");
        }
Example #2
0
        public void DumpImages(object sender, EventArgs e)
        {
            if (sender is BackgroundWorker)
            {
                worker = sender as BackgroundWorker;
            }
            else
            {
                worker = null;
            }

            List <string> imageFiles = new List <string>();
            string        filter     = ".gim";
            int           counter    = 0; // used to add a number to each image name, just in case disambiguation is required

            GenerateFileListFiltered(Path.Combine(ProjectFolder.GetRootDir(), ProjectFolder.unpackedGameFilesDir), imageFiles, filter);

            foreach (var file in imageFiles)
            {
                string fileName              = Path.GetFileNameWithoutExtension(file);
                string targetFilePath        = Path.Combine(ImageHandler.GetImagesDir(), fileName);
                string targetFilePathPostFix = string.Format("_{0}.png", counter.ToString());
                targetFilePath += targetFilePathPostFix;

                counter++;



                if (worker != null)
                {
                    if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                    {
                        return;
                    }
                }

                if (!ImageHandler.ConvertImage(file, targetFilePath))
                {
                    continue;
                }

                var gimBuildInstructions = new GIMBuildObject();
                gimBuildInstructions.originalFileLocation = Path.Combine(ProjectFolder.editableGameFiesDir, ImageHandler.imagesDir, Path.GetFileName(targetFilePath));
                gimBuildInstructions.targetFileLocation   = Path.Combine(ProjectFolder.reassembledGameFilesDir, ProjectFolder.GetSubPath(file, Path.Combine(ProjectFolder.GetRootDir(), ProjectFolder.unpackedGameFilesDir))); // this is a bad line
                gimBuildInstructions.checksumType         = Checksum.MD5;

                try
                {
                    FileStream   fs = new FileStream(targetFilePath, FileMode.Open);
                    BinaryReader br = new BinaryReader(fs);

                    byte[] imageData = br.ReadBytes((int)br.BaseStream.Length);
                    gimBuildInstructions.checksumValue = Checksums.GetMD5(imageData);

                    br.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    continue;
                }

                gimBuildInstructions.SerializeToDisk(Path.Combine(ProjectFolder.GetRootDir(), ProjectFolder.buildScriptsDir, Path.GetFileName(targetFilePath)));

                if (worker != null)
                {
                    double progress = ((double)counter / (double)imageFiles.Count) * 100;

                    worker.ReportProgress((int)progress);
                }
            }
        }