コード例 #1
0
ファイル: Import.cs プロジェクト: yalaier/Sims4Tools
        void importStream(myDataFormat data, bool useName, bool rename, bool compress, DuplicateHandling dups, bool select)
        {
            if (useName && data.tgin.ResName != null && data.tgin.ResName.Length > 0)
            {
                browserWidget1.ResourceName(data.tgin.ResInstance, data.tgin.ResName, true, rename);
            }

            IResourceIndexEntry rie = NewResource((TGIBlock)data.tgin, new MemoryStream(data.data), dups, compress);

            if (rie != null)
            {
                browserWidget1.Add(rie, select);
            }
        }
コード例 #2
0
ファイル: Import.cs プロジェクト: yalaier/Sims4Tools
        void importSingle(myDataFormat data)
        {
            ResourceDetails ir = new ResourceDetails(/*20120820 CurrentPackage.Find(x => x.ResourceType == 0x0166038C) != null/**/ true, true);

            ir.Filename = data.tgin;
            DialogResult dr = ir.ShowDialog();

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

            data.tgin = ir;
            importStream(data, ir.UseName, ir.AllowRename, ir.Compress, ir.Replace ? DuplicateHandling.replace : DuplicateHandling.reject, true);
        }
コード例 #3
0
ファイル: Import.cs プロジェクト: yalaier/Sims4Tools
        private void resourcePaste()
        {
            try
            {
                this.Enabled = false;
                if (Clipboard.ContainsData(myDataFormatSingleFile))
                {
                    IFormatter   formatter = new BinaryFormatter();
                    MemoryStream ms        = Clipboard.GetData(myDataFormatSingleFile) as MemoryStream;
                    myDataFormat d         = (myDataFormat)formatter.Deserialize(ms);
                    ms.Close();

                    importSingle(d);
                }
                else if (Clipboard.ContainsData(myDataFormatBatch))
                {
                    IFormatter          formatter = new BinaryFormatter();
                    MemoryStream        ms        = Clipboard.GetData(myDataFormatBatch) as MemoryStream;
                    List <myDataFormat> l         = (List <myDataFormat>)formatter.Deserialize(ms);
                    ms.Close();

                    importBatch(l);
                }
                else if (Clipboard.ContainsFileDropList())
                {
                    System.Collections.Specialized.StringCollection fileDrop = Clipboard.GetFileDropList();
                    if (fileDrop == null || fileDrop.Count == 0)
                    {
                        return;
                    }

                    if (fileDrop.Count == 1)
                    {
                        importSingle(fileDrop[0], "Resource->Paste");
                    }
                    else
                    {
                        string[] batch = new string[fileDrop.Count];
                        for (int i = 0; i < fileDrop.Count; i++)
                        {
                            batch[i] = fileDrop[i];
                        }
                        importBatch(batch, "Resource->Paste");
                    }
                }
            }
            finally { this.Enabled = true; }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: Kuree/Sims4Tools
        //private void resourceCut() { resourceCopy(); if (browserWidget1.SelectedResource != null) package.DeleteResource(browserWidget1.SelectedResource); }

        private void resourceCopy()
        {
            if (browserWidget1.SelectedResources.Count == 0) return;

            Application.UseWaitCursor = true;
            Application.DoEvents();
            try
            {
                if (browserWidget1.SelectedResources.Count == 1)
                {
                    myDataFormat d = new myDataFormat();
                    d.tgin = browserWidget1.SelectedResource as AResourceIndexEntry;
                    d.tgin.ResName = resourceName;
                    d.data = s4pi.WrapperDealer.WrapperDealer.GetResource(0, CurrentPackage, browserWidget1.SelectedResource, true).AsBytes;//Don't need wrapper

                    IFormatter formatter = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    formatter.Serialize(ms, d);
                    DataFormats.Format f = DataFormats.GetFormat(myDataFormatSingleFile);
                    Clipboard.SetData(myDataFormatSingleFile, ms);
                }
                else
                {
                    List<myDataFormat> l = new List<myDataFormat>();
                    foreach (IResourceIndexEntry rie in browserWidget1.SelectedResources)
                    {
                        myDataFormat d = new myDataFormat();
                        d.tgin = rie as AResourceIndexEntry;
                        d.tgin.ResName = browserWidget1.ResourceName(rie);
                        d.data = s4pi.WrapperDealer.WrapperDealer.GetResource(0, CurrentPackage, rie, true).AsBytes;//Don't need wrapper
                        l.Add(d);
                    }

                    IFormatter formatter = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    formatter.Serialize(ms, l);
                    DataFormats.Format f = DataFormats.GetFormat(myDataFormatBatch);
                    Clipboard.SetData(myDataFormatBatch, ms);
                }
            }
            finally { Application.UseWaitCursor = false; Application.DoEvents(); }
        }
コード例 #5
0
ファイル: Import.cs プロジェクト: yalaier/Sims4Tools
        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();
            }
        }
コード例 #6
0
ファイル: Import.cs プロジェクト: dwalternatio/Sims4Tools
        void importStream(myDataFormat data, bool useName, bool rename, bool compress, DuplicateHandling dups, bool select)
        {
            if (useName && data.tgin.ResName != null && data.tgin.ResName.Length > 0)
                browserWidget1.ResourceName(data.tgin.ResInstance, data.tgin.ResName, true, rename);

            IResourceIndexEntry rie = NewResource((TGIBlock)data.tgin, new MemoryStream(data.data), dups, compress);
            if (rie != null) browserWidget1.Add(rie, select);
        }
コード例 #7
0
ファイル: Import.cs プロジェクト: dwalternatio/Sims4Tools
        void importSingle(myDataFormat data)
        {
            ResourceDetails ir = new ResourceDetails(/*20120820 CurrentPackage.Find(x => x.ResourceType == 0x0166038C) != null/**/true, true);
            ir.Filename = data.tgin;
            DialogResult dr = ir.ShowDialog();
            if (dr != DialogResult.OK) return;

            data.tgin = ir;
            importStream(data, ir.UseName, ir.AllowRename, ir.Compress, ir.Replace ? DuplicateHandling.replace : DuplicateHandling.reject, true);
        }
コード例 #8
0
ファイル: Import.cs プロジェクト: dwalternatio/Sims4Tools
        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();
            }
        }