Beispiel #1
0
        private void OpenWeMadeLibrary()
        {
            if (WemadeLibrary != null)
            {
                WemadeLibrary = null;
            }

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

            switch (openType)
            {
            case Common.OpenType.Open:
                WemadeLibrary = new FileStructures.WeMadeLibrary(FilePath);
                break;

            case Common.OpenType.New:
                WemadeLibrary = new FileStructures.WeMadeLibrary(FilePath);
                // WemadeLibrary.Save();
                break;

            case Common.OpenType.None:
            default:
                MessageBox.Show("Invalid Open Type.");
                this.Dispose();
                break;
            }
            this.Text = System.IO.Path.GetFileName(FilePath);

            PreviewListView.VirtualListSize = WemadeLibrary.Images.Length;
            PreviewListView.RedrawItems(0, PreviewListView.Items.Count - 1, true);

            if (PreviewListView.Items.Count > 0)
            {
                PreviewListView.Items[0].Selected = true;
            }

            lbImageCount.Caption = string.Format("Images: {0}", WemadeLibrary.Images.Length);
            //  GC.Collect();
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_sleepThread)
            {
                listLog.Items.Add(string.Format("<b>[{0}]</b> Sleeping thread.", DateTime.Now)); // Log output
                listLog.TopIndex = listLog.Items.Count - 1;

                Thread.Sleep(1500); // Sleep thread to allow form to be drawn
            }

            BackgroundWorker worker = sender as BackgroundWorker;

            int[]      ImageIndexs;
            List <int> imageIndexes = new List <int>();

            Common.Gender _currentGender = Common.Gender.None;

            // Data folder refers to office standard libraries
            if (_folder == Common.FolderType.Data)
            {
                switch (_officialMirType)
                {
                case Common.OfficialMirType.None:
                    break;

                case Common.OfficialMirType.Armour:
                    for (int i = 0; i < Files.Count; i++)
                    {
                        try
                        {
                            if (Files[i].ToLower().EndsWith(".wil") || Files[i].ToLower().EndsWith(".wzl") || Files[i].ToLower().EndsWith(".miz"))     // Skip if not valid file type
                            {
                                if (Files[i].ToLower().Contains("effect") || !Files[i].ToLower().Contains("hum"))
                                {
                                    continue;                                                                                   // Skip effect libraries and ones that are not armour libraries (to the best we can due to naming conventions)
                                }
                                _tempWeMadeLibrary = new FileStructures.WeMadeLibrary(Files[i], false);

                                int ArmourCount = (((_tempWeMadeLibrary.Images.Length) / 1200));     // Get the amount of armours in the library

                                // Loop through the armour count and add the relative male / female index numbers to initialize later
                                for (int j = 0; j < ArmourCount; j++)
                                {
                                    imageIndexes.Add((j * 1200) + ((byte)_direction * 8));
                                    imageIndexes.Add((j * 1200) + 600 + ((byte)_direction * 8));
                                }

                                _tempWeMadeLibrary.InitializeLibraryImages(imageIndexes.ToArray());     // Initialize armour indexes

                                // Loop through armour indexes and pull the image to report
                                for (int k = 0; k < imageIndexes.Count; k += 2)
                                {
                                    backgroundWorker1.ReportProgress((int)Math.Round((double)(0)), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", Files[i], "Male"), 0, Files[i], (Image)_tempWeMadeLibrary.Images[imageIndexes[k]].Image));
                                    backgroundWorker1.ReportProgress((int)Math.Round((double)(0)), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", Files[i], "Female"), 0, Files[i], (Image)_tempWeMadeLibrary.Images[imageIndexes[k + 1]].Image));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            // TODO: Add error reporting code
                            continue;
                        }
                    }
                    break;

                case Common.OfficialMirType.Weapon:
                    for (int i = 0; i < Files.Count; i++)
                    {
                        try
                        {
                            if (Files[i].ToLower().EndsWith(".wil") || Files[i].ToLower().EndsWith(".wzl") || Files[i].ToLower().EndsWith(".miz"))
                            {
                                if (Files[i].ToLower().Contains("effect") || !Files[i].ToLower().Contains("weapon"))
                                {
                                    continue;
                                }

                                _tempWeMadeLibrary = new FileStructures.WeMadeLibrary(Files[i], false);

                                int WeaponCount = (((_tempWeMadeLibrary.Images.Length) / 1200));

                                for (int j = 0; j < WeaponCount; j++)
                                {
                                    imageIndexes.Add((j * 1200) + ((byte)_direction * 8));
                                    imageIndexes.Add((j * 1200) + 600 + ((byte)_direction * 8));
                                }

                                _tempWeMadeLibrary.InitializeLibraryImages(imageIndexes.ToArray());

                                for (int k = 0; k < imageIndexes.Count; k += 2)
                                {
                                    backgroundWorker1.ReportProgress((int)Math.Round((double)(0)), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", Files[i], "Male"), 0, Files[i], (Image)_tempWeMadeLibrary.Images[imageIndexes[k]].Image));
                                    backgroundWorker1.ReportProgress((int)Math.Round((double)(0)), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", Files[i], "Female"), 0, Files[i], (Image)_tempWeMadeLibrary.Images[imageIndexes[k + 1]].Image));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            // TODO: Add error reporting code
                            continue;
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            else if (_folder != Common.FolderType.None)
            {
                for (int i = 0; i < FilesCount; i++)
                {
                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        break;
                    }
                    if (_sleepThread)
                    {
                        Thread.Sleep(20);               // Sleep thread to allow rows to be drawn
                    }
                    try
                    {
                        switch (_folder)
                        {
                        case Common.FolderType.CArmour:
                            switch (_gender)
                            {
                            case Common.Gender.Male:
                                ImageIndexs = new int[] { 0 + ((byte)_direction * 4) };
                                break;

                            case Common.Gender.Female:
                                ImageIndexs = new int[] { 0 + ((byte)_direction * 4) + (int)Common.LibraryImageOffsets.CArmour };
                                break;

                            case Common.Gender.Both:
                                ImageIndexs = new int[] { 0 + ((byte)_direction * 4), 0 + ((byte)_direction * 4) + (int)Common.LibraryImageOffsets.CArmour };
                                break;

                            default:
                                ImageIndexs = new int[] { 0 };
                                break;
                            }
                            _tempCrystalV2Library = new FileStructures.MLibraryV2(_dir + @"\" + i.ToString("00") + ".Lib", ImageIndexs);
                            break;

                        case Common.FolderType.CWeapon:
                            switch (_gender)
                            {
                            case Common.Gender.Male:
                                ImageIndexs = new int[] { 0 + ((byte)_direction * 4) };
                                break;

                            case Common.Gender.Female:
                                ImageIndexs = new int[] { 0 + ((byte)_direction * 4) + (int)Common.LibraryImageOffsets.CWeapon };
                                break;

                            case Common.Gender.Both:
                                ImageIndexs = new int[] { 0 + ((byte)_direction * 4), 0 + ((byte)_direction * 4) + (int)Common.LibraryImageOffsets.CWeapon };
                                break;

                            default:
                                ImageIndexs = new int[] { 0 };
                                break;
                            }
                            _tempCrystalV2Library = new FileStructures.MLibraryV2(_dir + @"\" + i.ToString("00") + ".Lib", ImageIndexs);
                            break;

                        case Common.FolderType.Monster:
                            ImageIndexs           = new int[] { 0 };
                            _tempCrystalV2Library = new FileStructures.MLibraryV2(_dir + @"\" + i.ToString("000") + ".Lib", ImageIndexs);
                            break;

                        default:
                            return;
                        }

                        for (int j = 0; j < ImageIndexs.Length; j++)
                        {
                            _currentGender = (j == 0) ? Common.Gender.Male : Common.Gender.Female; // Used for displaying gender in error
                            FileStructures.MLibraryV2.MImage _tempImage = _tempCrystalV2Library.Images[ImageIndexs[j]];

                            // Image processing
                            if (_cropImage == true)
                            {
                                _tempImage.Image = Functions.CropImage.CropTransparent(_tempImage.Image).Image;
                            }
                            if (_tempImage.Image == null || _tempImage.Width == 0)
                            {
                                _tempImage.Image = Properties.Resources.ImageError;                                                    // Replace new bitmap with error image
                            }
                            backgroundWorker1.ReportProgress((int)Math.Round((double)(100 * (i + 1)) / FilesCount), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", _tempCrystalV2Library.FileName, _currentGender), 0, _tempCrystalV2Library.FileName, (Image)_tempImage.Image));
                        }
                        GC.Collect();
                    }
                    catch (Exception ex)
                    {
                        backgroundWorker1.ReportProgress((int)Math.Round((double)(100 * (i + 1)) / FilesCount), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", _tempCrystalV2Library.FileName, _currentGender), 0, _tempCrystalV2Library.FileName, (Image)Properties.Resources.ImageError));
                        continue;
                    }
                }
            }
            else
            {
                for (int i = 0; i < Files.Count; i++)
                {
                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        break;
                    }
                    if (_sleepThread)
                    {
                        Thread.Sleep(20);               // Sleep thread to allow rows to be drawn
                    }
                    try
                    {
                        _tempCrystalV2Library = new FileStructures.MLibraryV2(Files[i], new int[] { 0 });

                        FileStructures.MLibraryV2.MImage _tempImage = _tempCrystalV2Library.Images[0];

                        // Image processing
                        if (_cropImage == true)
                        {
                            _tempImage.Image = Functions.CropImage.CropTransparent(_tempImage.Image).Image;
                        }
                        if (_tempImage.Image == null || _tempImage.Width == 0)
                        {
                            _tempImage.Image = Properties.Resources.ImageError;                                                    // Replace new bitmap with error image
                        }
                        backgroundWorker1.ReportProgress((int)Math.Round((double)(100 * (i + 1)) / (Files.Count)), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", _tempCrystalV2Library.FileName, _gender), 0, _tempCrystalV2Library.FileName, (Image)_tempImage.Image));

                        GC.Collect();
                    }
                    catch (Exception ex)
                    {
                        backgroundWorker1.ReportProgress((int)Math.Round((double)(100 * (i + 1)) / FilesCount), new ImageListBoxItem(null, string.Format("{0}\nGender: {1}", _tempCrystalV2Library.FileName, _gender), 0, _tempCrystalV2Library.FileName, (Image)Properties.Resources.ImageError));
                        continue;
                    }
                }
            }
            GC.Collect();
        }