-
Notifications
You must be signed in to change notification settings - Fork 450
Expand file tree
/
Copy pathLuaAutocompleteInstaller.cs
More file actions
101 lines (84 loc) · 2.85 KB
/
LuaAutocompleteInstaller.cs
File metadata and controls
101 lines (84 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.IO;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public class LuaAutocompleteInstaller
{
public enum TextEditors
{
Sublime2,
NotePad,
}
public bool IsInstalled(TextEditors editor)
{
return editor switch
{
TextEditors.Sublime2 => IsSublimeInstalled(),
TextEditors.NotePad => IsNotepadInstalled(),
_ => false,
};
}
public bool IsBizLuaRegistered(TextEditors editor)
{
return editor switch
{
TextEditors.Sublime2 => IsBizLuaSublimeInstalled(),
TextEditors.NotePad => IsBizLuaNotepadInstalled(),
_ => false,
};
}
public void InstallBizLua(TextEditors editor, LuaDocumentation docs)
{
switch (editor)
{
case TextEditors.Sublime2:
InstallBizLuaToSublime2(docs);
break;
case TextEditors.NotePad:
InstallBizLuaToNotepad(docs);
break;
}
}
private string AppDataFolder => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
private string ProgramFilesFolder => Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
private bool IsSublimeInstalled()
{
// The most likely location of the app, eventually we should consider looking through the registry or installed apps as a more robust way to detect it;
string exePath = Path.Combine(ProgramFilesFolder, @"Sublime Text 2\sublime_text.exe");
return File.Exists(exePath);
}
private bool IsNotepadInstalled()
{
// The most likely location of the app, eventually we should consider looking through the registry or installed apps as a more robust way to detect it;
string exePath = Path.Combine(ProgramFilesFolder, @"Notepad++\notepad++.exe");
return File.Exists(exePath);
}
private readonly string SublimeLuaPath = @"Sublime Text 2\Packages\Lua";
private readonly string SublimeCompletionsFilename = "bizhawk.lua.sublime-completions";
private bool IsBizLuaSublimeInstalled()
{
var bizCompletions = Path.Combine(AppDataFolder, SublimeLuaPath, SublimeCompletionsFilename);
return File.Exists(bizCompletions);
}
private readonly string NotepadPath = "TODO";
private readonly string NotepadAutoCompleteFileName = "TODO";
private bool IsBizLuaNotepadInstalled()
{
var bizCompletions = Path.Combine(AppDataFolder, NotepadPath, NotepadAutoCompleteFileName);
return File.Exists(bizCompletions);
}
private void InstallBizLuaToSublime2(LuaDocumentation docs)
{
var bizCompletions = Path.Combine(AppDataFolder, SublimeLuaPath, SublimeCompletionsFilename);
var text = docs.ToSublime2CompletionList();
File.WriteAllText(bizCompletions, text);
}
private void InstallBizLuaToNotepad(LuaDocumentation docs)
{
var bizAutocomplete = Path.Combine(AppDataFolder, NotepadPath, NotepadAutoCompleteFileName);
var text = docs.ToNotepadPlusPlusAutoComplete();
// TODO
//File.WriteAllText(bizCompletions, text);
}
}
}