diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-03-14 20:25:48 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-03-14 20:25:48 +0300 |
commit | d503da34e2723090b1de92f152d11ed13c3273b7 (patch) | |
tree | 5d8e8d164b8ebfc6ba6550872cbf248848120edd /SelectModsForm.cs | |
parent | 2827c2c9ff81c3340c96600c209fc4fafe5a15f6 (diff) |
We can see installed mods now
Diffstat (limited to 'SelectModsForm.cs')
-rw-r--r-- | SelectModsForm.cs | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/SelectModsForm.cs b/SelectModsForm.cs index 424dc650..e87a41c1 100644 --- a/SelectModsForm.cs +++ b/SelectModsForm.cs @@ -15,20 +15,44 @@ namespace com.clusterrr.hakchi_gui private readonly string usermodsDirectory;
private readonly string[] readmeFiles;
- public SelectModsForm()
+ public SelectModsForm(bool loadInstalledMods = false)
{
InitializeComponent();
baseDirectory = MainForm.BaseDirectory;
usermodsDirectory = Path.Combine(baseDirectory, "user_mods");
var modsList = new List<string>();
- if (Directory.Exists(usermodsDirectory))
+ if (loadInstalledMods && MainForm.Clovershell.IsOnline)
{
- modsList.AddRange(from m
- in Directory.GetDirectories(usermodsDirectory, "*.hmod", SearchOption.TopDirectoryOnly)
- select Path.GetFileNameWithoutExtension(m));
- modsList.AddRange(from m
- in Directory.GetFiles(usermodsDirectory, "*.hmod", SearchOption.TopDirectoryOnly)
- select Path.GetFileNameWithoutExtension(m));
+ var mods = new MemoryStream();
+ MainForm.Clovershell.Execute("ls /var/lib/hakchi/hmod/uninstall-*", null, mods, null, 1000, true);
+ mods.Seek(0, SeekOrigin.Begin);
+ var modsarr = new byte[mods.Length];
+ mods.Read(modsarr, 0, (int)mods.Length);
+ var modsstr = Encoding.UTF8.GetString(modsarr, 0, modsarr.Length);
+ var installedMods = modsstr.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
+ foreach (var mod in installedMods)
+ {
+ var modname = mod;
+ int pos;
+ while ((pos = modname.IndexOf("/")) >= 0)
+ modname = modname.Substring(pos + 1);
+ modname = modname.Substring("uninstall-".Length);
+ if (MainForm.InternalMods.Contains(modname))
+ continue;
+ modsList.Add(modname);
+ }
+ }
+ else
+ {
+ if (Directory.Exists(usermodsDirectory))
+ {
+ modsList.AddRange(from m
+ in Directory.GetDirectories(usermodsDirectory, "*.hmod", SearchOption.TopDirectoryOnly)
+ select Path.GetFileNameWithoutExtension(m));
+ modsList.AddRange(from m
+ in Directory.GetFiles(usermodsDirectory, "*.hmod", SearchOption.TopDirectoryOnly)
+ select Path.GetFileNameWithoutExtension(m));
+ }
}
readmeFiles = new string[] { "readme.txt", "readme.md", "readme" };
checkedListBoxMods.Items.Clear();
|