示例#1
0
文件: LMain.cs 项目: zixinren/wzl
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenLibraryDialog.Filter = "(*.wzl;*.wzx)|*.wzl;*.wzx|所有文件(*.*)|*.*";  //(*.txt)|*.txt|所有文件(*.*)|*.*”

            if (OpenLibraryDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            ClearInterface();
            ImageList.Images.Clear();
            PreviewListView.Items.Clear();
            _indexList.Clear();

            if (_library != null)
            {
                _library.Close();
            }
            _library = new MLibrary(OpenLibraryDialog.FileName);
            PreviewListView.VirtualListSize = _library.Images.Count;

            // Show .Lib path in application title.
            this.Text = OpenLibraryDialog.FileName.ToString();

            PreviewListView.SelectedIndices.Clear();

            if (PreviewListView.Items.Count > 0)
            {
                PreviewListView.Items[0].Selected = true;
            }
        }
示例#2
0
        private void countBlanksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenLibraryDialog.Multiselect = true;
            if (OpenLibraryDialog.ShowDialog() != DialogResult.OK)
            {
                OpenLibraryDialog.Multiselect = false;
                return;
            }
            OpenLibraryDialog.Multiselect = false;

            MLibrary.Load = false;
            int count = 0;

            for (int i = 0; i < OpenLibraryDialog.FileNames.Length; i++)
            {
                MLibrary library = new MLibrary(OpenLibraryDialog.FileNames[i]);

                for (int x = 0; x < library.Count; x++)
                {
                    if (library.Images[x].Length <= 8)
                    {
                        count++;
                    }
                }
                library.Close();
            }
            MLibrary.Load = true;


            MessageBox.Show(count.ToString());
        }
示例#3
0
        private void convertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenWeMadeDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            toolStripProgressBar.Maximum = OpenWeMadeDialog.FileNames.Length;
            toolStripProgressBar.Value   = 0;

            try
            {
                ParallelOptions options = new ParallelOptions {
                    MaxDegreeOfParallelism = 1
                };
                Parallel.For(0, OpenWeMadeDialog.FileNames.Length, options, i =>
                {
                    if (Path.GetExtension(OpenWeMadeDialog.FileNames[i]).ToUpper() == ".WTL")
                    {
                        WTLLibrary WTLlib = new WTLLibrary(OpenWeMadeDialog.FileNames[i]);
                        WTLlib.ToMLibrary();
                    }
                    else if (Path.GetExtension(OpenWeMadeDialog.FileNames[i]).ToUpper() == ".LIB")
                    {
                        FileStream stream   = new FileStream(OpenWeMadeDialog.FileNames[i], FileMode.Open, FileAccess.ReadWrite);
                        BinaryReader reader = new BinaryReader(stream);
                        int CurrentVersion  = reader.ReadInt32();
                        stream.Close();
                        stream.Dispose();
                        reader.Dispose();
                        if (CurrentVersion == 1)
                        {
                            MLibrary v1Lib = new MLibrary(OpenWeMadeDialog.FileNames[i]);
                            v1Lib.ToMLibrary();
                        }
                        else
                        {
                            MLibraryV2 v2Lib = new MLibraryV2(OpenWeMadeDialog.FileNames[i]);
                            v2Lib.ToMLibrary();
                        }
                    }
                    else
                    {
                        WeMadeLibrary WILlib = new WeMadeLibrary(OpenWeMadeDialog.FileNames[i]);
                        WILlib.ToMLibrary();
                    }
                    toolStripProgressBar.Value++;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            toolStripProgressBar.Value = 0;

            MessageBox.Show(string.Format("Successfully converted {0} {1}",
                                          (OpenWeMadeDialog.FileNames.Length).ToString(),
                                          (OpenWeMadeDialog.FileNames.Length > 1) ? "libraries" : "library"));
        }
示例#4
0
        private void copyToToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (PreviewListView.SelectedIndices.Count == 0)
            {
                return;
            }
            if (SaveLibraryDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            MLibrary tempLibrary = new MLibrary(SaveLibraryDialog.FileName);

            List <int> copyList = new List <int>();


            for (int i = 0; i < PreviewListView.SelectedIndices.Count; i++)
            {
                copyList.Add(PreviewListView.SelectedIndices[i]);
            }

            copyList.Sort();
            for (int i = 0; i < copyList.Count; i++)
            {
                MLibrary.MImage image = _library.GetMImage(copyList[i]);
                tempLibrary.AddImage(image.Image, image.X, image.Y);
            }

            tempLibrary.Save();
        }
示例#5
0
        public static void ProcessDir(string sourceDir, int recursionLvl, string outputDir)
        {
            if (recursionLvl <= HowDeepToScan)
            {
                // Process the list of files found in the directory.
                string[] fileEntries = Directory.GetFiles(sourceDir);
                foreach (string fileName in fileEntries)
                {
                    if (Directory.Exists(outputDir) != true) Directory.CreateDirectory(outputDir);
                    MLibraryv0 OldLibrary = new MLibraryv0(fileName);
                    MLibrary NewLibrary = new MLibrary(outputDir + Path.GetFileName(fileName)) { Images = new List<MLibrary.MImage>(), IndexList = new List<int>(), Count = OldLibrary.Images.Count }; ;
                    for (int i = 0; i < OldLibrary.Images.Count; i++)
                        NewLibrary.Images.Add(null);
                    for (int j = 0; j < OldLibrary.Images.Count; j++)
                    {
                        MLibraryv0.MImage oldimage = OldLibrary.GetMImage(j);
                        NewLibrary.Images[j] = new MLibrary.MImage(oldimage.FBytes,oldimage.Width, oldimage.Height) { X = oldimage.X, Y = oldimage.Y };
                    }
                    NewLibrary.Save();
                    for (int i = 0; i < NewLibrary.Images.Count; i++)
                    {
                        if (NewLibrary.Images[i].Preview != null)
                            NewLibrary.Images[i].Preview.Dispose();
                        if (NewLibrary.Images[i].Image != null)
                            NewLibrary.Images[i].Image.Dispose();
                        if (NewLibrary.Images[i].MaskImage != null)
                            NewLibrary.Images[i].MaskImage.Dispose();
                    }
                    for (int i = 0; i < OldLibrary.Images.Count; i++)
                    {
                        if (OldLibrary.Images[i].Preview != null)
                            OldLibrary.Images[i].Preview.Dispose();
                        if (OldLibrary.Images[i].Image != null)
                            OldLibrary.Images[i].Image.Dispose();
                    }
                    NewLibrary.Images.Clear();
                    NewLibrary.IndexList.Clear();
                    OldLibrary.Images.Clear();
                    OldLibrary.IndexList.Clear();
                    NewLibrary.Close();
                    OldLibrary.Close();
                    NewLibrary = null;
                    OldLibrary = null;

                 }

                // Recurse into subdirectories of this directory.
                string[] subdirEntries = Directory.GetDirectories(sourceDir);
                foreach (string subdir in subdirEntries)
                {
                    // Do not iterate through reparse points
                    if (Path.GetFileName(Path.GetFullPath(subdir).TrimEnd(Path.DirectorySeparatorChar)) == Path.GetFileName(Path.GetFullPath(outputDir).TrimEnd(Path.DirectorySeparatorChar))) continue;
                    if ((File.GetAttributes(subdir) &
                         FileAttributes.ReparsePoint) !=
                             FileAttributes.ReparsePoint)
                    ProcessDir(subdir, recursionLvl + 1, outputDir + " \\" + Path.GetFileName(Path.GetFullPath(subdir).TrimEnd(Path.DirectorySeparatorChar)) + "\\");
                }
            }
        }
示例#6
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (SaveLibraryDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (_library != null)
            {
                _library.Close();
            }
            _library = new MLibrary(SaveLibraryDialog.FileName);
            PreviewListView.VirtualListSize = 0;
        }
示例#7
0
        private void convertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenWeMadeDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            toolStripProgressBar.Maximum = OpenWeMadeDialog.FileNames.Length;
            toolStripProgressBar.Value   = 0;

            try
            {
                ParallelOptions options = new ParallelOptions {
                    MaxDegreeOfParallelism = 8
                };
                Parallel.For(0, OpenWeMadeDialog.FileNames.Length, options, i =>
                {
                    if (Path.GetExtension(OpenWeMadeDialog.FileNames[i]) == ".wtl")
                    {
                        WTLLibrary WTLlib = new WTLLibrary(OpenWeMadeDialog.FileNames[i]);
                        WTLlib.ToMLibrary();
                    }
                    else if (Path.GetExtension(OpenWeMadeDialog.FileNames[i]) == ".Lib")
                    {
                        MLibrary v1Lib = new MLibrary(OpenWeMadeDialog.FileNames[i]);
                        v1Lib.ToMLibrary();
                    }
                    else
                    {
                        WeMadeLibrary WILlib = new WeMadeLibrary(OpenWeMadeDialog.FileNames[i]);
                        WILlib.ToMLibrary();
                    }
                    toolStripProgressBar.Value++;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            toolStripProgressBar.Value = 0;

            MessageBox.Show(string.Format("Successfully converted {0} {1}",
                                          (OpenWeMadeDialog.FileNames.Length).ToString(),
                                          (OpenWeMadeDialog.FileNames.Length > 1) ? "libraries" : "library"));
        }
示例#8
0
        public void ToMLibrary()
        {
            string fileName = Path.ChangeExtension(_fileName, ".Lib");

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            MLibrary library = new MLibrary(fileName)
            {
                Images = new List <MLibrary.MImage>(), IndexList = new List <int>(), Count = Images.Length
            };

            for (int i = 0; i < library.Count; i++)
            {
                library.Images.Add(null);
            }

            ParallelOptions options = new ParallelOptions {
                MaxDegreeOfParallelism = 8
            };

            Parallel.For(0, Images.Length, options, i =>
            {
                WeMadeImage image = Images[i];
                if (image.HasMask)
                {
                    library.Images[i] = new MLibrary.MImage(image.Image, image.MaskImage)
                    {
                        X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0, MaskX = image.X, MaskY = image.Y
                    }
                }
                ;
                else
                {
                    library.Images[i] = new MLibrary.MImage(image.Image)
                    {
                        X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow? (byte)1: (byte)0
                    }
                };
            });

            library.Save();
        }
示例#9
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenLibraryDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            ClearInterface();
            ImageList.Images.Clear();
            PreviewListView.Items.Clear();
            _indexList.Clear();

            if (_library != null)
            {
                _library.Close();
            }
            _library = new MLibrary(OpenLibraryDialog.FileName);
            PreviewListView.VirtualListSize = _library.Images.Count;
        }
示例#10
0
        public void ToMLibrary()
        {
            string fileName = Path.ChangeExtension(_fileName, ".Lib");

            if (File.Exists(fileName))
                File.Delete(fileName);

            MLibrary library = new MLibrary(fileName) {Images = new List<MLibrary.MImage>(), IndexList = new List<int>(), Count = Images.Length};

            for (int i = 0; i < library.Count; i++)
                library.Images.Add(null);

            ParallelOptions options = new ParallelOptions {MaxDegreeOfParallelism = 8};
            Parallel.For(0, Images.Length, options, i =>
                {
                    WeMadeImage image = Images[i];
                    library.Images[i] = new MLibrary.MImage(image.Image) {X = image.X, Y = image.Y};
                });

            library.Save();
        }
示例#11
0
        private void countBlanksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenLibraryDialog.Multiselect = true;
            if (OpenLibraryDialog.ShowDialog() != DialogResult.OK)
            {
                OpenLibraryDialog.Multiselect = false;
                return;
            }
            OpenLibraryDialog.Multiselect = false;

            MLibrary.Load = false;
            int count = 0;
            for (int i = 0; i < OpenLibraryDialog.FileNames.Length; i++)
            {

                MLibrary library = new MLibrary(OpenLibraryDialog.FileNames[i]);

                for (int x = 0; x < library.Count; x++)
                {
                    if (library.Images[x].Length <= 8)
                        count++;
                }
                library.Close();
            }
            MLibrary.Load = true;

            MessageBox.Show(count.ToString());
        }
示例#12
0
        private void copyToToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (PreviewListView.SelectedIndices.Count == 0) return;
            if (SaveLibraryDialog.ShowDialog() != DialogResult.OK) return;

            MLibrary tempLibrary = new MLibrary(SaveLibraryDialog.FileName);

            List<int> copyList = new List<int>();

            for (int i = 0; i < PreviewListView.SelectedIndices.Count; i++)
                copyList.Add(PreviewListView.SelectedIndices[i]);

            copyList.Sort();
            for (int i = 0; i < copyList.Count; i++)
            {
                MLibrary.MImage image = _library.GetMImage(copyList[i]);
                tempLibrary.AddImage(image.Image, image.X, image.Y);
            }

            tempLibrary.Save();
        }
示例#13
0
文件: LMain.cs 项目: mstation/mir2
        private void convertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenWeMadeDialog.ShowDialog() != DialogResult.OK) return;

            toolStripProgressBar.Maximum = OpenWeMadeDialog.FileNames.Length;
            toolStripProgressBar.Value = 0;

            try
            {
                ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 8 };
                Parallel.For(0, OpenWeMadeDialog.FileNames.Length, options, i =>
                            {
                                if (Path.GetExtension(OpenWeMadeDialog.FileNames[i]) == ".wtl")
                                {
                                    WTLLibrary WTLlib = new WTLLibrary(OpenWeMadeDialog.FileNames[i]);
                                    WTLlib.ToMLibrary();
                                }
                                else if (Path.GetExtension(OpenWeMadeDialog.FileNames[i]) == ".Lib")
                                {
                                    MLibrary v1Lib = new MLibrary(OpenWeMadeDialog.FileNames[i]);
                                    v1Lib.ToMLibrary();
                                }
                                else
                                {
                                    WeMadeLibrary WILlib = new WeMadeLibrary(OpenWeMadeDialog.FileNames[i]);
                                    WILlib.ToMLibrary();
                                }
                                toolStripProgressBar.Value++;
                            });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            toolStripProgressBar.Value = 0;

            MessageBox.Show(string.Format("Successfully converted {0} {1}",
                (OpenWeMadeDialog.FileNames.Length).ToString(),
                (OpenWeMadeDialog.FileNames.Length > 1) ? "libraries" : "library"));
        }
示例#14
0
        public void ToMLibrary()
        {
            string fileName = Path.ChangeExtension(_fileName, ".Lib");

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            MLibrary library = new MLibrary(fileName)
            {
                Images = new List <MLibrary.MImage>(), IndexList = new List <int>(), Count = Images.Length
            };

            //library.Save();

            for (int i = 0; i < library.Count; i++)
            {
                library.Images.Add(null);
            }

            ParallelOptions options = new ParallelOptions {
                MaxDegreeOfParallelism = 8
            };

            try
            {
                Parallel.For(0, Images.Length, options, i =>
                {
                    WeMadeImage image = Images[i];
                    if (image.HasMask)
                    {
                        library.Images[i] = new MLibrary.MImage(image.Image, image.MaskImage)
                        {
                            X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0, MaskX = image.X, MaskY = image.Y
                        }
                    }
                    ;
                    else
                    {
                        library.Images[i] = new MLibrary.MImage(image.Image)
                        {
                            X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0
                        }
                    };
                });
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                library.Save();
            }

            // Operation finished.
            // System.Windows.Forms.MessageBox.Show("Converted " + fileName + " successfully.",
            //    "Wemade Information",
            //        System.Windows.Forms.MessageBoxButtons.OK,
            //            System.Windows.Forms.MessageBoxIcon.Information,
            //                System.Windows.Forms.MessageBoxDefaultButton.Button1);
        }
示例#15
0
文件: LMain.cs 项目: quttap/mir2
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (Path.GetExtension(files[0]).ToUpper() == ".WIL" ||
                Path.GetExtension(files[0]).ToUpper() == ".WZL" ||
                Path.GetExtension(files[0]).ToUpper() == ".MIZ")
            {
                try
                {
                    ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 8 };
                    Parallel.For(0, files.Length, options, i =>
                    {
                        if (Path.GetExtension(files[i]) == ".wtl")
                        {
                            WTLLibrary WTLlib = new WTLLibrary(files[i]);
                            WTLlib.ToMLibrary();
                        }
                        else
                        {
                            WeMadeLibrary WILlib = new WeMadeLibrary(files[i]);
                            WILlib.ToMLibrary();
                        }
                        toolStripProgressBar.Value++;
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                toolStripProgressBar.Value = 0;

                MessageBox.Show(
                    string.Format("Successfully converted {0} {1}",
                    (OpenWeMadeDialog.FileNames.Length).ToString(),
                    (OpenWeMadeDialog.FileNames.Length > 1) ? "libraries" : "library"));
            }
            else if (Path.GetExtension(files[0]).ToUpper() == ".LIB")
            {
                ClearInterface();
                ImageList.Images.Clear();
                PreviewListView.Items.Clear();
                _indexList.Clear();

                if (_library != null) _library.Close();
                _library = new MLibrary(files[0]);
                PreviewListView.VirtualListSize = _library.Images.Count;
                PreviewListView.RedrawItems(0, PreviewListView.Items.Count - 1, true);

                // Show .Lib path in application title.
                this.Text = files[0].ToString();
            }
            else
            {
                return;
            }
        }
示例#16
0
        private void MergeButton_Click(object sender, EventArgs e)
        {
            if (_library == null)
            {
                return;
            }
            if (_library.FileName == null)
            {
                return;
            }

            string value = "1000";
            int    temp  = 0;

            if (InputBox("Merge Blanks", "How Many Images Per Object:", ref value) == DialogResult.OK)
            {
                if (!int.TryParse(value, out temp))
                {
                    MessageBox.Show("Should be a numeric value");
                    return;
                }
                if (temp <= 0)
                {
                    MessageBox.Show("Must be atleast 1");
                    return;
                }
                newImages = temp;
            }

            _library.AddBlanks(newImages);

            if (OpenMergeDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            toolStripProgressBar.Maximum = OpenMergeDialog.FileNames.Length;
            toolStripProgressBar.Value   = 0;

            try
            {
                foreach (string file in OpenMergeDialog.FileNames)
                {
                    if (Path.GetExtension(file).ToUpper() == ".ZL")
                    {
                        Mir3Library newLib = new Mir3Library(file);
                        foreach (Mir3Library.Mir3Image image in newLib.Images)
                        {
                            _library.AddImage(image.Image, image.OffSetX, image.OffSetY);
                        }
                    }
                    else if (Path.GetExtension(file).ToUpper() == ".WTL")
                    {
                        WTLLibrary WTLlib = new WTLLibrary(file);
                        WTLlib.MergeToMLibrary(_library, newImages);
                    }
                    else if (Path.GetExtension(file).ToUpper() == ".LIB")
                    {
                        FileStream   stream         = new FileStream(file, FileMode.Open, FileAccess.ReadWrite);
                        BinaryReader reader         = new BinaryReader(stream);
                        int          CurrentVersion = reader.ReadInt32();
                        stream.Close();
                        stream.Dispose();
                        reader.Dispose();
                        if (CurrentVersion == 1)
                        {
                            MLibrary v1Lib = new MLibrary(file);
                            v1Lib.MergeToMLibrary(_library, newImages);
                        }
                        else
                        {
                            MLibraryV2 v2Lib = new MLibraryV2(file);
                            v2Lib.MergeToMLibrary(_library, newImages);
                        }
                    }
                    else
                    {
                        WeMadeLibrary WILlib = new WeMadeLibrary(file);
                        WILlib.MergeToMLibrary(_library, newImages);
                    }
                    toolStripProgressBar.Value++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            toolStripProgressBar.Value = 0;

            MessageBox.Show(string.Format("Successfully merged {0} {1}",
                                          (OpenMergeDialog.FileNames.Length).ToString(),
                                          (OpenMergeDialog.FileNames.Length > 1) ? "libraries" : "library"));

            ImageList.Images.Clear();
            _indexList.Clear();
            PreviewListView.VirtualListSize = _library.Images.Count;

            _library.Save(_library.FileName);
        }
示例#17
0
文件: LMain.cs 项目: quttap/mir2
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenLibraryDialog.ShowDialog() != DialogResult.OK) return;

            ClearInterface();
            ImageList.Images.Clear();
            PreviewListView.Items.Clear();
            _indexList.Clear();

            if (_library != null) _library.Close();
            _library = new MLibrary(OpenLibraryDialog.FileName);
            PreviewListView.VirtualListSize = _library.Images.Count;

            // Show .Lib path in application title.
            this.Text = OpenLibraryDialog.FileName.ToString();

            PreviewListView.SelectedIndices.Clear();

            if (PreviewListView.Items.Count > 0)
                PreviewListView.Items[0].Selected = true;
        }
示例#18
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (SaveLibraryDialog.ShowDialog() != DialogResult.OK) return;

            if (_library != null) _library.Close();
            _library = new MLibrary(SaveLibraryDialog.FileName);
            PreviewListView.VirtualListSize = 0;
        }
示例#19
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenLibraryDialog.ShowDialog() != DialogResult.OK)
                return;

            ClearInterface();
            ImageList.Images.Clear();
            PreviewListView.Items.Clear();
            _indexList.Clear();

            if (_library != null) _library.Close();
            _library = new MLibrary(OpenLibraryDialog.FileName);
            PreviewListView.VirtualListSize = _library.Images.Count;
        }
示例#20
0
文件: LMain.cs 项目: zixinren/wzl
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (Path.GetExtension(files[0]).ToUpper() == ".WIL" ||
                Path.GetExtension(files[0]).ToUpper() == ".WZL" ||
                Path.GetExtension(files[0]).ToUpper() == ".MIZ")
            {
                try
                {
                    ParallelOptions options = new ParallelOptions {
                        MaxDegreeOfParallelism = 8
                    };
                    Parallel.For(0, files.Length, options, i =>
                    {
                        if (Path.GetExtension(files[i]) == ".wtl")
                        {
                            WTLLibrary WTLlib = new WTLLibrary(files[i]);
                            WTLlib.ToMLibrary();
                        }
                        else
                        {
                            WeMadeLibrary WILlib = new WeMadeLibrary(files[i]);
                            WILlib.ToMLibrary();
                        }
                        toolStripProgressBar.Value++;
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                toolStripProgressBar.Value = 0;

                MessageBox.Show(
                    string.Format("Successfully converted {0} {1}",
                                  (OpenWeMadeDialog.FileNames.Length).ToString(),
                                  (OpenWeMadeDialog.FileNames.Length > 1) ? "libraries" : "library"));
            }
            else if (Path.GetExtension(files[0]).ToUpper() == ".LIB")
            {
                ClearInterface();
                ImageList.Images.Clear();
                PreviewListView.Items.Clear();
                _indexList.Clear();

                if (_library != null)
                {
                    _library.Close();
                }
                _library = new MLibrary(files[0]);
                PreviewListView.VirtualListSize = _library.Images.Count;
                PreviewListView.RedrawItems(0, PreviewListView.Items.Count - 1, true);

                // Show .Lib path in application title.
                this.Text = files[0].ToString();
            }
            else
            {
                return;
            }
        }
示例#21
0
文件: WTLLibrary.cs 项目: quttap/mir2
        public void ToMLibrary()
        {
            string fileName = Path.ChangeExtension(_fileName, ".Lib");

            if (File.Exists(fileName))
                File.Delete(fileName);

            MLibrary library = new MLibrary(fileName) { Images = new List<MLibrary.MImage>(), IndexList = new List<int>(), Count = Images.Length };
            //library.Save();

            for (int i = 0; i < library.Count; i++)
                library.Images.Add(null);

            ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 8 };
            try
            {
                Parallel.For(0, Images.Length, options, i =>
                {
                    WTLImage image = Images[i];
                    if (image.HasMask)
                        library.Images[i] = new MLibrary.MImage(image.Image, image.MaskImage) { X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.Shadow, MaskX = image.MaskX, MaskY = image.MaskY };
                    else
                        library.Images[i] = new MLibrary.MImage(image.Image) { X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.Shadow };
                });
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                library.Save();
            }

            // Operation finished.
            // System.Windows.Forms.MessageBox.Show("Converted " + fileName + " successfully.",
            //    "Shanda Information",
            //        System.Windows.Forms.MessageBoxButtons.OK,
            //            System.Windows.Forms.MessageBoxIcon.Information,
            //                System.Windows.Forms.MessageBoxDefaultButton.Button1);
        }
示例#22
0
        public static void ProcessDir(string sourceDir, int recursionLvl, string outputDir)
        {
            if (recursionLvl <= HowDeepToScan)
            {
                // Process the list of files found in the directory.
                string[] fileEntries = Directory.GetFiles(sourceDir);
                foreach (string fileName in fileEntries)
                {
                    if (Path.GetExtension(fileName) != ".lib")
                    {
                        continue;
                    }

                    if (Directory.Exists(outputDir) != true)
                    {
                        Directory.CreateDirectory(outputDir);
                    }
                    MLibraryv0 OldLibrary = new MLibraryv0(fileName);
                    MLibrary   NewLibrary = new MLibrary(outputDir + Path.GetFileName(fileName))
                    {
                        Images = new List <MLibrary.MImage>(), IndexList = new List <int>(), Count = OldLibrary.Images.Count
                    };;
                    for (int i = 0; i < OldLibrary.Images.Count; i++)
                    {
                        NewLibrary.Images.Add(null);
                    }
                    for (int j = 0; j < OldLibrary.Images.Count; j++)
                    {
                        MLibraryv0.MImage oldimage = OldLibrary.GetMImage(j);
                        NewLibrary.Images[j] = new MLibrary.MImage(oldimage.FBytes, oldimage.Width, oldimage.Height)
                        {
                            X = oldimage.X, Y = oldimage.Y
                        };
                    }
                    NewLibrary.Save();
                    for (int i = 0; i < NewLibrary.Images.Count; i++)
                    {
                        if (NewLibrary.Images[i].Preview != null)
                        {
                            NewLibrary.Images[i].Preview.Dispose();
                        }
                        if (NewLibrary.Images[i].Image != null)
                        {
                            NewLibrary.Images[i].Image.Dispose();
                        }
                        if (NewLibrary.Images[i].MaskImage != null)
                        {
                            NewLibrary.Images[i].MaskImage.Dispose();
                        }
                    }
                    for (int i = 0; i < OldLibrary.Images.Count; i++)
                    {
                        if (OldLibrary.Images[i].Preview != null)
                        {
                            OldLibrary.Images[i].Preview.Dispose();
                        }
                        if (OldLibrary.Images[i].Image != null)
                        {
                            OldLibrary.Images[i].Image.Dispose();
                        }
                    }
                    NewLibrary.Images.Clear();
                    NewLibrary.IndexList.Clear();
                    OldLibrary.Images.Clear();
                    OldLibrary.IndexList.Clear();
                    NewLibrary.Close();
                    OldLibrary.Close();
                    NewLibrary = null;
                    OldLibrary = null;
                }



                // Recurse into subdirectories of this directory.
                string[] subdirEntries = Directory.GetDirectories(sourceDir);
                foreach (string subdir in subdirEntries)
                {
                    // Do not iterate through reparse points
                    if (Path.GetFileName(Path.GetFullPath(subdir).TrimEnd(Path.DirectorySeparatorChar)) == Path.GetFileName(Path.GetFullPath(outputDir).TrimEnd(Path.DirectorySeparatorChar)))
                    {
                        continue;
                    }
                    if ((File.GetAttributes(subdir) &
                         FileAttributes.ReparsePoint) !=
                        FileAttributes.ReparsePoint)
                    {
                        ProcessDir(subdir, recursionLvl + 1, outputDir + " \\" + Path.GetFileName(Path.GetFullPath(subdir).TrimEnd(Path.DirectorySeparatorChar)) + "\\");
                    }
                }
            }
        }