Esempio n. 1
0
        public SelectForm(bool onlyInstalledMods, bool allowDropMods, string[] filesToAdd = null)
        {
            InitializeComponent();
            this.onlyInstalledMods = onlyInstalledMods;

            switch (ConfigIni.Instance.hmodListSort)
            {
            case ListSort.Category:
                categoryToolStripMenuItem.Checked = true;
                break;

            case ListSort.EmulatedSystem:
                emulatedSystemToolStripMenuItem.Checked = true;
                break;

            case ListSort.Creator:
                creatorToolStripMenuItem.Checked = true;
                break;
            }

            hmods.AddRange(Hmod.GetMods(hakchi.CanInteract && onlyInstalledMods, this));

            populateList();

            if (filesToAdd != null)
            {
                AddMods(filesToAdd);
            }
            this.AllowDrop = allowDropMods;
        }
Esempio n. 2
0
 private void showModInExplorerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listViewHmods.SelectedItems.Count > 0)
     {
         Hmod selectedHmod = (Hmod)(listViewHmods.SelectedItems[0].Tag);
         if (selectedHmod.PresentInUserMods())
         {
             string args = $"/select, \"{selectedHmod.HmodPath}\"";
             Process.Start("explorer.exe", args);
         }
     }
 }
Esempio n. 3
0
 private void listViewHmods_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     if (e.Item != null && listViewHmods.SelectedItems.Count > 0)
     {
         Hmod hmod = (Hmod)(listViewHmods.SelectedItems[0].Tag);
         if (hmodDisplayed != hmod.RawName)
         {
             readmeControl1.setReadme(hmod.Name, hmod.Readme);
         }
     }
     else
     {
         readmeControl1.clear();
     }
 }
Esempio n. 4
0
 private void deleteModFromDiskToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem selectedItem in listViewHmods.SelectedItems)
     {
         Hmod selectedHmod = (Hmod)(selectedItem.Tag);
         if (selectedHmod.PresentInUserMods())
         {
             if (selectedHmod.isFile)
             {
                 File.Delete(selectedHmod.HmodPath);
             }
             else
             {
                 Directory.Delete(selectedHmod.HmodPath, true);
             }
             hmods.Remove(selectedHmod);
         }
     }
     populateList();
 }
Esempio n. 5
0
        private void AddMods(string[] files, bool moveHmod = false)
        {
            foreach (var file in files)
            {
                var ext = Path.GetExtension(file).ToLower();
                if (ext == ".hmod")
                {
                    var target = Path.Combine(usermodsDirectory, $"{Hmod.GetCleanName(Path.GetFileNameWithoutExtension(file), true)}.hmod");

                    if (File.Exists(target))
                    {
                        File.Delete(target);
                    }

                    if (Directory.Exists(target))
                    {
                        Directory.Delete(target, true);
                    }

                    if (file != target)
                    {
                        if (Directory.Exists(file))
                        {
                            if (moveHmod)
                            {
                                Directory.Move(file, target);
                            }
                            else
                            {
                                Shared.DirectoryCopy(file, target, true, false, true, false);
                            }
                        }
                        else
                        {
                            if (moveHmod)
                            {
                                File.Move(file, target);
                            }
                            else
                            {
                                File.Copy(file, target, true);
                            }
                        }
                    }

                    var rawName = Path.GetFileNameWithoutExtension(target);

                    hmods.RemoveAll(m => m.RawName == rawName);
                    hmods.Add(new Hmod(rawName));
                }
                else if (ext == ".7z" || ext == ".zip" || ext == ".rar" || ext == ".tar")
                {
                    var newHmods = new List <string>();
                    using (var extractor = ArchiveFactory.Open(file))
                    {
                        TempHelpers.doWithTempFolder(temp =>
                        {
                            extractor.WriteToDirectory(temp, new ExtractionOptions()
                            {
                                ExtractFullPath = true
                            });
                            AddMods(Directory.EnumerateDirectories(temp, "*.hmod", SearchOption.AllDirectories).ToArray(), true);
                            AddMods(Directory.EnumerateFiles(temp, "*.hmod", SearchOption.AllDirectories).ToArray(), true);
                        }, true, usermodsDirectory);
                    }
                }
            }

            populateList();
        }