예제 #1
0
        public void closePackage()
        {
            if (imppkg != null)
            {
                imppkg.Dispose();
                imppkg = null;
                if (lrie != null)
                {
                    lrie.Clear();
                }
                res = null;
            }

            if (!openedFromSTBL_File)
            {
                linkLabel1.Visible = false;
            }
        }
예제 #2
0
        private void closeAndSavePackage(bool save = true)
        {
            if (save)
            {
                if (isTextChanged && pathOpened)
                {
                    SaveSTBL(false, openedFromSTBL_File);
                }
                else if (isTextChanged && dataGridView1.Rows.Count > 0)
                {
                    SaveSTBL(true, openedFromSTBL_File);
                }
            }

            dataGridView1.DataSource = null;
            dataGridView1.Columns.Add("Column1", "");
            dataGridView1.Columns.Add("Column2", "");
            RestoreDataGridViewSettings();

            switch (Thread.CurrentThread.CurrentUICulture.ThreeLetterWindowsLanguageName)
            {
            case "CHS":
            case "ZHI":
                filenameLabel.Text = "未打开任何文件。";
                break;

            case "CHT":
            case "ZHH":
            case "ZHM":
                filenameLabel.Text = "未開啟任何檔案。";
                break;

            default:
                filenameLabel.Text = "No file is opened.";
                break;
            }

            languageLable.Text = string.Empty;
            publicPath         = string.Empty;
            pathOpened         = false;
            canAlsoSave        = false;
            isTextChanged      = false;


            openedFromSTBL_File = true;
            packageElId         = 0;
            if (imppkg != null)
            {
                imppkg.Dispose();
                imppkg = null;
                lrie.Clear();
            }

            res = null;
        }
예제 #3
0
        private void Sort_mods()
        {
            list_of_mods.Items.Clear();
            thumbnail_bitmaps.Clear();
            string[]      folders   = Directory.GetDirectories(mod_folder_path);
            string[]      mod_names = Directory.GetFiles(mod_folder_path);
            string        current_body_type;
            List <string> new_folders = new List <string>();

            Custom_Message_Box("Please wait, this can take some time. " + mod_names.Length.ToString() + " mods need to be sorted.");

            foreach (string name in mod_names)
            {
                current_body_type = "";
                if (!name.Contains(".package"))
                {
                    continue;
                }
                IPackage now_open      = Package.OpenPackage(0, name);
                string   only_mod_name = Regex.Match(name, regex_pattern).ToString();

                foreach (IResourceIndexEntry r in now_open.GetResourceList)
                {
                    if (flags.Contains(r.ResourceType))
                    {
                        CASPartResource.CASPartResource text_file = (CASPartResource.CASPartResource)WrapperDealer.GetResource(1, now_open, r);

                        current_body_type = text_file.BodyType.ToString();

                        break;
                    }
                    else if (types.Contains(r.ResourceType))
                    {
                        current_body_type = "Objects";

                        break;
                    }
                }

                now_open.Dispose();

                if (folders.Contains(current_body_type) || new_folders.Contains(current_body_type))
                {
                    File.Move(name, mod_folder_path + "\\" + current_body_type + "\\" + only_mod_name + ".package");
                }
                else
                {
                    Directory.CreateDirectory(mod_folder_path + "\\" + current_body_type);
                    new_folders.Add(current_body_type);
                    File.Move(name, mod_folder_path + "\\" + current_body_type + "\\" + only_mod_name + ".package");
                }
            }
            Custom_Message_Box("All mods have been sorted!");
        }
        public void Dispose()
        {
            RootFolder.Dispose();
            _package.Dispose();

            if (_watcher != null)
            {
                _watcher.Changed -= OnFileChange;
                _watcher.Deleted -= OnFileChange;
                _watcher.Renamed -= OnFileChange;
                _watcher.Dispose();
            }
        }
예제 #5
0
 private void Remove_file()
 {
     try
     {
         object mod_in_list  = list_of_mods.SelectedItem;
         int    now_selected = list_of_mods.SelectedIndex;
         string to_delete    = names[now_selected];
         p.Dispose();
         list_of_mods.Items.Remove(mod_in_list);
         FileSystem.DeleteFile(to_delete, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
         names.RemoveAt(now_selected);
     }
     catch (Exception)
     {
         Custom_Message_Box("Please select a mod from the list before deleting it.");
     }
 }
예제 #6
0
        private void list_of_mods_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string now_selected          = list_of_mods.SelectedItem.ToString();
                int    index_of_now_selected = list_of_mods.Items.IndexOf(list_of_mods.SelectedItem);

                tb_mod_name.Text = now_selected;

                p = Package.OpenPackage(0, names[index_of_now_selected]);
                Fill_Image_Array(p);
                Fill_Details(p);
                p.Dispose();
            }
            catch (Exception)
            {
                img_thumbnail.Source = BitmapFrame.Create(new Uri("pack://application:,,,/Clear.bmp"));
                img_counter.Content  = "1/1";
                tb_mod_name.Text     = null;
                tb_flags.Text        = null;
                tb_age_gender.Text   = null;
                tb_body_type.Text    = null;
            }
        }
예제 #7
0
 public void Dispose()
 {
     RootFolder.Dispose();
     _package.Dispose();
 }
예제 #8
0
        private void importPackagesCommon(string[] packageList, string title, DuplicateHandling dups, bool compress,
                                          bool useNames                         = false,
                                          bool rename                           = false,
                                          List <uint> dupsList                  = null,
                                          AutoSaveState autoSaveState           = AutoSaveState.Ask,
                                          IList <IResourceIndexEntry> selection = null
                                          )
        {
            bool     CPuseNames = controlPanel1.UseNames;
            DateTime now        = DateTime.UtcNow;

            bool autoSave = false;

            if (autoSaveState == AutoSaveState.Ask)
            {
                switch (CopyableMessageBox.Show("Auto-save current package after each package imported?", title,
                                                CopyableMessageBoxButtons.YesNoCancel, CopyableMessageBoxIcon.Question))
                {
                case 0: autoSave = true; break;

                case 2: return;
                }
            }
            else
            {
                autoSave = autoSaveState == AutoSaveState.Always;
            }

            try
            {
                browserWidget1.Visible = false;
                controlPanel1.UseNames = false;

                bool skipAll = false;
                foreach (string filename in packageList)
                {
                    if (Filename != null && Filename.Length > 0 && Path.GetFullPath(Filename).Equals(Path.GetFullPath(filename)))
                    {
                        CopyableMessageBox.Show("Skipping current package.", importPackagesDialog.Title);
                        continue;
                    }

                    lbProgress.Text = "Importing " + Path.GetFileNameWithoutExtension(filename) + "...";
                    Application.DoEvents();
                    IPackage imppkg = null;
                    try
                    {
                        imppkg = Package.OpenPackage(0, filename);
                    }
                    catch (InvalidDataException ex)
                    {
                        if (skipAll)
                        {
                            continue;
                        }
                        int btn = CopyableMessageBox.Show(String.Format("Could not open package {0}.\n{1}", Path.GetFileName(filename), ex.Message),
                                                          title, CopyableMessageBoxIcon.Error, new List <string>(new string[] {
                            "Skip this", "Skip all", "Abort"
                        }), 0, 0);
                        if (btn == 0)
                        {
                            continue;
                        }
                        if (btn == 1)
                        {
                            skipAll = true; continue;
                        }
                        break;
                    }
                    try
                    {
                        List <Tuple <myDataFormat, DuplicateHandling> > limp = new List <Tuple <myDataFormat, DuplicateHandling> >();
                        List <IResourceIndexEntry> lrie = selection == null
                            ? imppkg.GetResourceList
                            : imppkg.FindAll(rie => selection.Any(tgt => ((AResourceKey)tgt).Equals(rie)));
                        progressBar1.Value   = 0;
                        progressBar1.Maximum = lrie.Count;
                        foreach (IResourceIndexEntry rie in lrie)
                        {
                            try
                            {
                                if (rie.ResourceType == 0x0166038C)//NMAP
                                {
                                    if (useNames)
                                    {
                                        browserWidget1.MergeNamemap(s4pi.WrapperDealer.WrapperDealer.GetResource(0, imppkg, rie) as IDictionary <ulong, string>, true, rename);
                                    }
                                }
                                else
                                {
                                    IResource res = s4pi.WrapperDealer.WrapperDealer.GetResource(0, imppkg, rie, true);

                                    myDataFormat impres = new myDataFormat()
                                    {
                                        tgin = rie as AResourceIndexEntry,
                                        data = res.AsBytes,
                                    };

                                    // dups Replace | Reject | Allow
                                    // dupsList null | list of allowable dup types
                                    DuplicateHandling dupThis =
                                        dups == DuplicateHandling.allow
                                            ? dupsList == null || dupsList.Contains(rie.ResourceType) ? DuplicateHandling.allow : DuplicateHandling.replace
                                            : dups;

                                    limp.Add(Tuple.Create(impres, dupThis));
                                    progressBar1.Value++;
                                    if (now.AddMilliseconds(100) < DateTime.UtcNow)
                                    {
                                        Application.DoEvents(); now = DateTime.UtcNow;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                string rk = "";
                                if (rie != null)
                                {
                                    rk = "(RK: " + rie + ")\n";
                                }
                                else
                                {
                                    rk = "(RK is null)\n";
                                }

                                CopyableMessageBox.IssueException(ex, "Could not import all resources - aborting.\n" + rk, title);
                                throw new IgnoredException(ex);
                            }
                        }
                        progressBar1.Value = 0;

                        IEnumerable <IResourceIndexEntry> rieList = limp
                                                                    .Select(x => NewResource((AResourceKey)x.Item1.tgin, new MemoryStream(x.Item1.data), x.Item2, compress))
                                                                    .Where(x => x != null);
                        browserWidget1.AddRange(rieList);
                    }
                    catch (IgnoredException) { break; }//just the thrown exception, stop looping
                    catch (Exception ex)
                    {
                        CopyableMessageBox.IssueException(ex, "Could not import all resources - aborting.\n", title);
                        break;
                    }
                    finally { imppkg.Dispose(); }//Package.ClosePackage(0, imppkg); }
                    if (autoSave)
                    {
                        if (!fileSave())
                        {
                            break;
                        }
                    }
                }
            }
            finally
            {
                lbProgress.Text        = "";
                progressBar1.Value     = 0;
                progressBar1.Maximum   = 0;
                controlPanel1.UseNames = CPuseNames;
                browserWidget1.Visible = true;
                ForceFocus.Focus(Application.OpenForms[0]);
                Application.DoEvents();
            }
        }
예제 #9
0
        private bool RotateImage(ref IPackage package)
        {
            var image = package.Images[0];
            var fileName = Path.GetTempFileName();
            image.SaveAs(fileName+".jpg", ImageType.Jpeg, 100);
            image.Dispose();

            var pic = Image.FromFile(fileName + ".jpg");
            pic.RotateFlip(RotateFlipType.Rotate90FlipNone);
            pic.Save(fileName + ".jpeg", ImageFormat.Jpeg);
            pic.Dispose();

            package.Dispose();
            package = null;

            var imageDevice = _scanInstance.OpenFileReader(fileName + ".jpeg");
            if (imageDevice == null) return false;
            imageDevice.ConfigName = "ScanInoPassportBy";
            package = _scanInstance.CreatePackage();
            if (package == null) return false;
            image = package.Scan(imageDevice, 0);
            return image != null;
        }