-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInstallationChecker.cs
More file actions
172 lines (159 loc) · 6.17 KB
/
InstallationChecker.cs
File metadata and controls
172 lines (159 loc) · 6.17 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.IO;
using UnityEngine;
using KSP.Localization;
namespace AfterSolarSystem
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
class ASSInstallationCheck : MonoBehaviour
{
public void Start()
{
try
{
ASS_InstallCheck();
}
catch (Exception ex)
{
Debug.Log("[AfterSolarSystem] ASSInstallationCheck.Start() caught an exception: " + ex);
}
finally
{
Destroy(this);
}
}
private void ASS_InstallCheck()
{
CheckTextures();
CheckPrincipia();
}
private void CheckTextures()
{
string szTextureFolderPath = $"{KSPUtil.ApplicationRootPath}GameData{Path.AltDirectorySeparatorChar}AfterSolarSystem-Textures";
string szUserMessage = Localizer.Format("#InstallationChecker_MissingTextures");
string title = Localizer.Format("#InstallationChecker_Title");
string buttonText = Localizer.Format("#InstallationChecker_DownloadAndExit");
if (!Directory.Exists(szTextureFolderPath))
{
Debug.Log("[AfterSolarSystem] No texture pack detected!");
PopupDialog.SpawnPopupDialog
(
new Vector2(0.0f, 0.0f),
new Vector2(0.0f, 0.0f),
new MultiOptionDialog
(
"ASS_InstallCheck",
szUserMessage,
title,
HighLogic.UISkin,
new Rect(0.25f, 0.75f, 320f, 80f),
new DialogGUIFlexibleSpace(),
new DialogGUIButton
(
buttonText,
delegate
{
OpenASSTexturesDownloadPage();
QuitGame();
},
140.0f,
30.0f,
true
)
),
false,
HighLogic.UISkin,
true,
string.Empty
);
}
}
private void CheckPrincipia()
{
string principiaFolderPath = $"{KSPUtil.ApplicationRootPath}GameData{Path.AltDirectorySeparatorChar}Principia";
string principiaFilePath = $"{principiaFolderPath}{Path.AltDirectorySeparatorChar}real_solar_system{Path.AltDirectorySeparatorChar}initial_state_jd_2433282_500000000.cfg";
if (Directory.Exists(principiaFolderPath) && File.Exists(principiaFilePath))
{
Debug.Log("[AfterSolarSystem] Conflicting Principia file detected!");
string warningMessage = Localizer.Format("#InstallationChecker_PrincipiaConflict");
string title = Localizer.Format("#InstallationChecker_Title");
string openAndExitButtonText = Localizer.Format("#InstallationChecker_OpenAndExit");
string closeButtonText = Localizer.Format("#InstallationChecker_Close");
PopupDialog.SpawnPopupDialog
(
new Vector2(0.0f, 0.0f),
new Vector2(0.0f, 0.0f),
new MultiOptionDialog
(
"ASS_PrincipiaCheck",
warningMessage,
title,
HighLogic.UISkin,
new Rect(0.25f, 0.75f, 320f, 80f),
new DialogGUIFlexibleSpace(),
new DialogGUIButton
(
openAndExitButtonText,
delegate
{
OpenPrincipiaFolder(principiaFilePath);
QuitGame();
},
140.0f,
30.0f,
true
),
new DialogGUIButton
(
closeButtonText,
delegate
{
Debug.Log("[AfterSolarSystem] User closed the Principia warning dialog.");
},
140.0f,
30.0f,
true
)
),
false,
HighLogic.UISkin,
true,
string.Empty
);
}
}
private void OpenASSTexturesDownloadPage()
{
Application.OpenURL("https://github.com/YWMKerman/AfterSolarSystem/releases");
}
private void OpenPrincipiaFolder(string filePath)
{
try
{
string folderPath = Path.GetDirectoryName(filePath);
if (Directory.Exists(folderPath))
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = folderPath,
UseShellExecute = true,
Verb = "open"
});
}
else
{
Debug.LogWarning("[AfterSolarSystem] The specified folder does not exist: " + folderPath);
}
}
catch (Exception ex)
{
Debug.LogError("[AfterSolarSystem] Failed to open folder: " + ex);
}
}
private void QuitGame()
{
Debug.Log("[AfterSolarSystem] Quitting the game due to critical installation issues.");
Application.Quit();
}
}
}