private void Specific_Mod_Settings_Click(object sender, RoutedEventArgs e)
        {
            var tag     = ((Button)sender).Tag.ToString();
            var modItem = ModItems.First(p => p.UUID == tag);

            if (EditModWindow == null)
            {
                return;
            }

            EditModWindow.InitEditMod(modItem);
            EditModWindow.EditedMod = (updatedMod) =>
            {
                if (updatedMod == null)
                {
                    return;
                }

                var modItemsList = ModItems.ToList();

                var index = modItemsList.FindIndex(p => p.UUID == updatedMod.UUID);
                modItemsList[index] = updatedMod;

                var saved = Shrek2MM.SaveMods(modItemsList);
                if (saved == false)
                {
                    MessageBox.Show("Failed to update mod list, this can be becaues of read/write permissions.");
                }

                ModItems.Clear();
                modItemsList.ForEach(mod => ModItems.Add(mod));
            };

            DialogHost.Show(EditModWindow.Content);
        }
        private async void Window_Initialized(object sender, EventArgs e)
        {
            RemoveModWindow = new RemoveModWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            EditModWindow = new EditModWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            SettingsWindow = new SettingsWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            var mods = Shrek2MM.LoadMods();

            if (mods == null)
            {
                MessageBox.Show("Failed to load Added Mods correctly, this might indicate that the JSON file is corrupted or damaged! Please close this application and ensure the JSON file isn't damaged in any way before proceeding.");
                Add_Mod_Button.IsEnabled = false;
                Play_Button.IsEnabled    = false;
                ModItemsList.ItemsSource = ModItems;
                return;
            }

            var extractedModLoader = await Shrek2MM.ExtractModLoader();

            if (extractedModLoader == false)
            {
                MessageBox.Show("Couldn't extract the Mod Loader which is embedded in the Shrek 2 Mod Manager Program. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                Add_Mod_Button.IsEnabled = false;
                Play_Button.IsEnabled    = false;
                ModItemsList.ItemsSource = ModItems;
                return;
            }

            mods.ForEach(mod => ModItems.Add(mod));

            ModItemsList.ItemsSource = ModItems;
        }
        private void Add_Mod_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new()
                {
                    Filter = "Shrek 2 Mod File (.dll)|*.dll|Shrek 2 Mod Zip (.zip)|*.zip"
                };
                ofd.ShowDialog();

                if (string.IsNullOrEmpty(ofd.FileName))
                {
                    return;
                }

                var modTitle  = System.IO.Path.GetFileNameWithoutExtension(ofd.FileName);
                var fileName  = System.IO.Path.GetFileName(ofd.FileName);
                var extension = System.IO.Path.GetExtension(ofd.FileName);
                var uuid      = Guid.NewGuid().ToString();

                var copied = Shrek2MM.CopyModToDataFolder(ofd.FileName, uuid);

                if (copied == false)
                {
                    MessageBox.Show("Couldn't add the selected mod. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                    return;
                }

                ModItems.Add(new Shrek2ModListItem(
                                 modTitle,
                                 extension == ".dll" ? Shrek2ModListItem.ModTypes.ModFile : Shrek2ModListItem.ModTypes.ModZip,
                                 true,
                                 uuid
                                 ));

                if (Shrek2MM.SaveMods(ModItems.ToList()) == false)
                {
                    MessageBox.Show("Failed to save the selected mod you wanted to add. We correctly copied the mod data but we couldn't save the metadata. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                    return;
                }
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                MessageBox.Show("Error occured when trying to add a mod. For more details check the Error Log in 'This PC/My Documents/Shrek 2 Mod Manager'.");
            }
        }
Exemplo n.º 4
0
        public static Int32 RegisterModItem(SObject modItem)
        {
            if (modItem.HasBeenRegistered)
            {
                Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
                return(modItem.RegisteredId);
            }
            Int32 newId = LowestModItemID;

            if (ModItems.Count > 0)
            {
                newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
            }
            ModItems.Add(newId, modItem);
            modItem.HasBeenRegistered = true;
            modItem.RegisteredId      = newId;
            return(newId);
        }
Exemplo n.º 5
0
        // ReSharper disable once UnusedMember.Local
        private static int RegisterModItem(SObject modItem)
        {
            if (modItem.HasBeenRegistered)
            {
                Log.AsyncR($"The item {modItem.Name} has already been registered with ID {modItem.RegisteredId}");
                return(modItem.RegisteredId);
            }
            var newId = LowestModItemID;

            if (ModItems.Count > 0)
            {
                newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
            }
            ModItems.Add(newId, modItem);
            modItem.HasBeenRegistered = true;
            modItem.RegisteredId      = newId;
            return(newId);
        }