Esempio n. 1
0
        public Mir3Library Convert()
        {
            string shadowPath = _fileName.Replace(".wtl", "_S.wtl");

            WTLLibrary shadowLibrary = null;

            if (File.Exists(shadowPath))
            {
                shadowLibrary = new WTLLibrary(shadowPath);
            }

            Mir3Library lib = new Mir3Library
            {
                Images = new Mir3Image[Images.Length]
            };

            for (int i = 0; i < Images.Length; i++)
            {
                MImage image = Images[i];
                if (image?.Texture == null)
                {
                    continue;
                }

                lib.Images[i] = image.Convert(shadowLibrary, i);
            }

            shadowLibrary?.Dispose();

            return(lib);
        }
Esempio n. 2
0
        private async void ConvertLibrariesButton_Click(object sender, EventArgs e)
        {
            DirectoryInfo directory = new DirectoryInfo((string)folderTextBox.Text);

            if (!directory.Exists)
            {
                return;
            }

            FileInfo[] targets = directory.GetFiles("*.WTL", SubFoldersCheckEdit.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            TotleCount    = targets.Length;
            ProgressCount = 0;

            if (targets.Length == 0)
            {
                return;
            }

            Task task = Task.Run(() =>
            {
                ParallelOptions po = new ParallelOptions {
                    MaxDegreeOfParallelism = 10
                };
                Parallel.For(0, targets.Length, po, i =>
                {
                    if (!targets[i].FullName.EndsWith("_S.wtl"))
                    {
                        using (WTLLibrary wtl = new WTLLibrary(targets[i].FullName))
                        {
                            Mir3Library library = wtl.Convert();

                            library.Save(Path.ChangeExtension(targets[i].FullName, @".Zl"));
                        }
                    }
                    Interlocked.Increment(ref ProgressCount);
                });
            });

            while (!task.IsCompleted)
            {
                UpdateProgress();

                await Task.Delay(100);
            }

            ProgressLabel.Text = "Compeleted.";
        }
Esempio n. 3
0
        private async void CreateLibrariesButton_Click(object sender, EventArgs e)
        {
            DirectoryInfo directory = new DirectoryInfo((string)folderTextBox.Text);

            if (!directory.Exists)
            {
                return;
            }

            DirectoryInfo[] targets = directory.GetDirectories("*.*", SubFoldersCheckEdit.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            if (targets.Length == 0)
            {
                targets = new[] { directory }
            }
            ;

            TotleCount    = targets.Length;
            ProgressCount = 0;

            if (targets.Length == 0)
            {
                return;
            }

            Task task = Task.Run(() =>
            {
                ParallelOptions po = new ParallelOptions {
                    MaxDegreeOfParallelism = 15
                };

                Parallel.For(0, targets.Length, po, i =>
                {
                    if (!File.Exists(targets[i].FullName + "\\Placements.txt"))
                    {
                        return;
                    }

                    string[] placements = File.ReadAllLines(targets[i].FullName + "\\Placements.txt");

                    Mir3Library lib = new Mir3Library {
                        Images = new Mir3Image[placements.Length]
                    };

                    ParallelOptions po1 = new ParallelOptions {
                        MaxDegreeOfParallelism = 15
                    };
                    Parallel.For(0, placements.Length, po1, index =>
                    {
                        string fileName = string.Format(targets[i].FullName + "\\{0:00000}.bmp", index);

                        if (!File.Exists(fileName))
                        {
                            return;
                        }

                        string[] placement = placements[index].Split(',');

                        short x = short.Parse(placement[0]);
                        short y = short.Parse(placement[1]);


                        using (Bitmap image = new Bitmap(fileName))
                        {
                            lib.Images[index] = new Mir3Image
                            {
                                Width   = (short)image.Width,
                                Height  = (short)image.Height,
                                OffSetX = x,
                                OffSetY = y,
                                Data    = MImage.GetBytes(image)
                            };
                        }
                    });

                    lib.Save(targets[i].FullName + ".Zl");

                    Interlocked.Increment(ref ProgressCount);
                });
            });

            while (!task.IsCompleted)
            {
                UpdateProgress();

                await Task.Delay(100);
            }

            ProgressLabel.Text = "Compeleted.";
        }