Пример #1
0
        async void save()
        {
            string buildDir = configMgr.GetDirectory("BuildDirectory", "Grim");
            string sprPath  = $"{buildDir}\\{sprName}";

            statusLb.Text = $"Writing {sprName} to disk";

            prgBar.Maximum = sprEntries.Count;

            using (StreamWriter sw = new StreamWriter(sprPath, false))
            {
                for (int i = 0; i < sprEntries.Count; i++)
                {
                    SprInfo sprInfo = sprEntries[i];

                    await Task.Run(() => {
                        sw.WriteLine(sprInfo.Name);
                        sw.WriteLine(sprInfo.FrameCount);
                        sw.WriteLine(sprInfo.Frames[0]);
                        sw.WriteLine($"{sprInfo.Height},{sprInfo.Width}");
                        sw.WriteLine(sprInfo.Unused);
                    });

                    if ((i * 100 / sprEntries.Count) != ((i - 1) * 100 / sprEntries.Count))
                    {
                        prgBar.Value = i;
                    }
                }
            }

            resetProgress();

            System.Threading.Thread.Sleep(1000);

            statusLb.Text = $"{sprEntries.Count} icons written to {sprName} successfully!";

            showIgnored();

            statusLb.Text = string.Empty;
        }
Пример #2
0
        async void compareEntries()
        {
            string dumpDir = configMgr.GetDirectory("DumpDirectory", "Grim");

            if (string.IsNullOrEmpty(dumpDir))
            {
                MessageBox.Show("Dump Directory cannot be empty! Please fill it in properly in the settings menu and try again!", "Invalid Dump Directory", MessageBoxButtons.OK, MessageBoxIcon.Error);

                statusLb.ResetText();

                resetProgress();

                return;
            }

            string jpgDir = $"{dumpDir}\\jpg\\";
            int    total  = sprEntries.Count;
            int    prg    = 0;

            bool showWarnings = configMgr["ShowWarnings", "SPR"];

            statusLb.Text = "Validating icon entries...";

            prgBar.Maximum = total;

            for (int i = sprEntries.Count - 1; i >= 0; i--)
            {
                SprInfo sprInfo = sprEntries[i];

                string filename = $"{jpgDir}{sprInfo.Frames[0]}";

                if (File.Exists(filename))
                {
                    await Task.Run(() => {
                        using (Bitmap bmp = new Bitmap(filename))
                        {
                            if (bmp != null)
                            {
                                Size size = bmp.Size;

                                sprInfo.SetSize(bmp.Size);

                                if (size != defSize)
                                {
                                    if (!ignoreSize && showWarnings)
                                    {
                                        ignored.Add(sprInfo.Name);
                                        sprEntries.Remove(sprInfo);

                                        MessageBox.Show($"Image size is invalid! {filename}\n\nImage Size: {size.Height},{size.Width}\nExpected Size: {defSize.Height},{defSize.Width}\n\nEntry has been removed!", "Invalid Image Size", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show($"Failed to load image {filename}", "Image Load Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                ignored.Add(sprInfo.Name);
                                sprEntries.Remove(sprInfo);
                            }
                        }
                    });
                }
                else
                {
                    ignored.Add(sprInfo.Name);

                    if (showWarnings)
                    {
                        MessageBox.Show($"No matching image for {sprInfo.Name} located in the dump directory!\n\nEntry has been removed!", "Missing Image Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    sprEntries.Remove(sprInfo);
                }

                prg = total - i;

                if ((prg * 100 / total) != ((prg - 1) * 100 / total))
                {
                    prgBar.Value = prg;
                }

                total          = sprEntries.Count;
                prgBar.Maximum = total;
            }

            statusLb.Text = $"{sprEntries.Count} icons verified!";

            resetProgress();

            save();
        }