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 MenuRenameSTBL_Click(object sender, EventArgs e)
        {
            string scriptName = null;

            foreach (ListItem item in ContentList.Items)
            {
                if (item is S3SAListItem)
                {
                    scriptName = item.Text;
                    break;
                }
            }

            TextInput dialog = new TextInput("HashName and Prefix", scriptName);

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            string[] results = dialog.Result.Split(' ');

            ulong result = FNV64.GetHash(results[0]);

            string orig = result.ToString("X16");

            int origValue = int.Parse(orig.Substring(0, 2), System.Globalization.NumberStyles.HexNumber, null);

            if (origValue < STBL.Count)
            {
                result++;

                orig = result.ToString("X16");
            }

            string part = orig.Substring(2);

            string prefix = null;

            if (results.Length > 1)
            {
                prefix = results[1] + " ";
            }

            foreach (string aPrefix in STBL.Keys)
            {
                ulong instance = Convert.ToUInt64("0x" + aPrefix + part, 16);

                bool found = false;
                foreach (IResourceIndexEntry entry in CurrentPackage.FindAll(key => ((key.ResourceType == (uint)ResourceType.STBL))))
                {
                    string instanceStr = entry["Instance"];

                    if (instanceStr.Substring(2, 2) == aPrefix)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    STBLListItem stblItem = new STBLListItem();

                    if (stblItem.AddNew(instance, CurrentPackage, true))
                    {
                        ContentList.Items.Add(stblItem);
                    }
                }
            }

            foreach (ListItem item in ContentList.Items)
            {
                if (!(item is STBLListItem))
                {
                    continue;
                }

                item.Instance = "0x" + STBL.GetPrefix(item.Instance) + part;

                item.Name = "Strings " + prefix + STBL.GetProperName(item.Instance);

                sChanged = true;
            }
        }
Exemple #3
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; }
        }