Exemple #1
0
        private bool SavePackage(bool prompt)
        {
            if (CurrentPackage == null)
            {
                return(true);
            }

            SavePreview();

            Application.UseWaitCursor = true;
            Application.DoEvents();
            try
            {
                if (sChanged)
                {
                    DialogResult result = DialogResult.Yes;
                    if (prompt)
                    {
                        result = MessageBox.Show("Do you wish to save your changes?", "Save", MessageBoxButtons.YesNoCancel);
                    }

                    switch (result)
                    {
                    case DialogResult.Yes:
                        IResourceIndexEntry keyEntry = CurrentPackage.Find(key => key.ResourceType == (uint)ResourceType._KEY);
                        if (keyEntry != null)
                        {
                            Dictionary <ulong, bool> existing = new Dictionary <ulong, bool>();

                            IList <IResourceIndexEntry> list = CurrentPackage.FindAll(value => { return(true); });
                            foreach (IResourceIndexEntry entry in list)
                            {
                                if (existing.ContainsKey(entry.Instance))
                                {
                                    continue;
                                }

                                existing.Add(entry.Instance, true);
                            }

                            NameMapResource.NameMapResource keyResource = CreateKeyResource(CurrentPackage) as NameMapResource.NameMapResource;

                            List <ulong> badKeys = new List <ulong>();

                            foreach (KeyValuePair <ulong, string> element in keyResource)
                            {
                                if (!existing.ContainsKey(element.Key))
                                {
                                    badKeys.Add(element.Key);
                                }
                            }

                            foreach (ulong key in badKeys)
                            {
                                keyResource.Remove(key);
                            }

                            CurrentPackage.ReplaceResource(keyEntry, keyResource);
                        }

                        CurrentPackage.SavePackage();

                        OnListElements(CurrentPackage);
                        break;

                    case DialogResult.No:
                        break;

                    case DialogResult.Cancel:
                        return(false);
                    }
                }
            }
            finally
            {
                Application.UseWaitCursor = false;
            }

            return(true);
        }
Exemple #2
0
        private void resourceImportAsDBC()
        {
            if (allowList.Count == 0)
            {
                allowList.AddRange(xmlList);
                allowList.AddRange(stblList);
                allowList.AddRange(nmapList);
            }
            try
            {
                this.Enabled = false;
                DialogResult dr = importPackagesDialog.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                AutoSaveState autoSaveState = AutoSaveState.Always;
                if (S4PIDemoFE.Properties.Settings.Default.AskDBCAutoSave)
                {
                    autoSaveState = AutoSaveState.Ask;
                }
                importPackagesCommon(importPackagesDialog.FileNames, importPackagesDialog.Title, DuplicateHandling.allow, true,
                                     useNames: true,
                                     dupsList: allowList,
                                     autoSaveState: autoSaveState);

                browserWidget1.Visible = false;
                lbProgress.Text        = "Doing DBC clean up...";

                Application.DoEvents();
                DateTime now = DateTime.UtcNow;
                IList <IResourceIndexEntry> lrie = dupsOnly(CurrentPackage.FindAll(x => stblList.Contains(x.ResourceType)));
                foreach (IResourceIndexEntry dup in lrie)
                {
                    IList <IResourceIndexEntry> ldups   = CurrentPackage.FindAll(rie => ((IResourceKey)dup).Equals(rie));
                    IResourceIndexEntry         newRie  = NewResource(dup, null, DuplicateHandling.allow, true);
                    IDictionary <ulong, string> newStbl = (IDictionary <ulong, string>)s4pi.WrapperDealer.WrapperDealer.GetResource(0, CurrentPackage, newRie);
                    foreach (IResourceIndexEntry rie in ldups)
                    {
                        IDictionary <ulong, string> oldStbl = (IDictionary <ulong, string>)s4pi.WrapperDealer.WrapperDealer.GetResource(0, CurrentPackage, rie);
                        foreach (var kvp in oldStbl)
                        {
                            if (!newStbl.ContainsKey(kvp.Key))
                            {
                                newStbl.Add(kvp);
                            }
                        }
                        rie.IsDeleted = true;
                        if (now.AddMilliseconds(100) < DateTime.UtcNow)
                        {
                            Application.DoEvents(); now = DateTime.UtcNow;
                        }
                    }
                    CurrentPackage.ReplaceResource(newRie, (IResource)newStbl);
                    browserWidget1.Add(newRie, false);
                }

                // Get rid of Sims3Pack resource that sneak in
                CurrentPackage.FindAll(x =>
                {
                    if (now.AddMilliseconds(100) < DateTime.UtcNow)
                    {
                        Application.DoEvents(); now = DateTime.UtcNow;
                    }
                    if (deleteList.Contains(x.ResourceType))
                    {
                        x.IsDeleted = true; return(false);
                    }
                    return(false);
                });

                // If there are any remaining duplicate XMLs, give up - they're too messy to fix automatically
                if (dupsOnly(CurrentPackage.FindAll(x => xmlList.Contains(x.ResourceType))).Count > 0)
                {
                    CopyableMessageBox.Show("Manual merge of XML files required.");
                }
            }
            finally { browserWidget1.Visible = true; lbProgress.Text = ""; Application.DoEvents(); this.Enabled = true; }
        }