@@ -10,24 +10,43 @@ namespace RA3.Tools
10
10
{
11
11
public class RA3Instance
12
12
{
13
+ /// <summary>
14
+ /// Private pre-defined name of QuickLoader.
15
+ /// </summary>
16
+ /// TODO: Download to AppData automatically.
13
17
private static readonly string _quickLoaderPath = "RA3.QuickLoader.exe" ;
14
- //
18
+
19
+ /// <summary>
20
+ /// Game install folder.
21
+ /// </summary>
15
22
public string GamePath ;
23
+
24
+ /// <summary>
25
+ /// Parameter passes to game.
26
+ /// </summary>
16
27
public string LaunchParamter ;
28
+
29
+ /// <summary>
30
+ /// Whether to use RA3BarLauncher to launch game.
31
+ /// </summary>
17
32
public bool UseBarLauncher ;
33
+
34
+ /// <summary>
35
+ /// Avaliable profiles of game user.
36
+ /// </summary>
18
37
public List < string > Profiles
19
38
{
20
39
get { return GetProfilesList ( ) ; }
21
40
}
22
- //
23
- public readonly ResourceFolder ModFolder = new ResourceFolder ( System . Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + " \\ Red Alert 3\\ Mods \\ " ) ;
24
- public readonly ResourceFolder ReplayFolder = new ResourceFolder ( System . Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + " \\ Red Alert 3\\ Replays \\ " ) ;
25
- public readonly ResourceFolder MapFolder = new ResourceFolder ( Environment . GetEnvironmentVariable ( "appdata" ) + " \\ Red Alert 3\\ Maps \\ " ) ;
26
- public readonly ResourceFolder ProfileFolder = new ResourceFolder ( Environment . GetEnvironmentVariable ( "appdata" ) + " \\ Red Alert 3 \\ Profiles \\ " ) ;
41
+ public readonly ResourceFolder ModFolder = new ResourceFolder ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "Red Alert 3" , "Mods" ) ) ;
42
+ public readonly ResourceFolder ReplayFolder = new ResourceFolder ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , " Red Alert 3" , "Replays" ) ) ;
43
+ public readonly ResourceFolder MapFolder = new ResourceFolder ( Path . Combine ( Environment . GetEnvironmentVariable ( "appdata" ) , " Red Alert 3" , "Maps" ) ) ;
44
+ public readonly ResourceFolder ProfileFolder = new ResourceFolder ( Path . Combine ( Environment . GetEnvironmentVariable ( "appdata" ) , " Red Alert 3" , "Profiles" ) ) ;
45
+
27
46
/// <summary>
28
- /// 红警3进程实例
47
+ /// Red-Alert 3 Game Instance.
29
48
/// </summary>
30
- /// <param name="gamePath">游戏路径(可选,为空则从注册表读取) </param>
49
+ /// <param name="gamePath">Game install folder. Will Read from Registry if empty. </param>
31
50
public RA3Instance ( string gamePath = "" )
32
51
{
33
52
//Read GamePath
@@ -39,8 +58,8 @@ public RA3Instance(string gamePath = "")
39
58
{
40
59
GamePath = gamePath ;
41
60
}
42
- //Check RA3.QuickLoader
43
- if ( File . Exists ( $ ". \\ { _quickLoaderPath } " ) )
61
+ //Check if RA3.QuickLoader is avaliable.
62
+ if ( File . Exists ( Path . GetFullPath ( _quickLoaderPath ) ) )
44
63
{
45
64
UseBarLauncher = true ;
46
65
}
@@ -51,33 +70,42 @@ public bool IsRA3PathValid()
51
70
{
52
71
try
53
72
{
54
- return Directory . EnumerateFiles ( GamePath , "RA3_*_1.12.SkuDef " ) . Any ( ) ;
73
+ return Directory . EnumerateFiles ( GamePath , "*.skudef " ) . Any ( ) ;
55
74
}
56
75
catch ( Exception ) { }
57
76
return false ;
58
77
}
59
78
60
79
public bool IsRA3FileValid ( )
61
80
{
62
- return false ;
81
+ throw new NotImplementedException ( ) ;
63
82
}
64
83
#endregion
65
84
66
85
#region Launch & Register
86
+ /// <summary>
87
+ /// launch game using skudef file directly.
88
+ /// </summary>
89
+ /// <param name="executablePath">e.g. ra3_1.12.game</param>
90
+ /// <param name="skudefPath">e.g. RA3_chinese_t_1.12.skudef</param>
91
+ public static void LaunchUsingSkudef ( string executablePath , string skudefPath )
92
+ {
93
+ if ( ! File . Exists ( executablePath ) )
94
+ throw new ArgumentException ( "Game not found." , nameof ( executablePath ) ) ;
95
+ if ( ! File . Exists ( skudefPath ) )
96
+ throw new ArgumentException ( "Skudef not found." ) ;
97
+ var startInfo = new ProcessStartInfo ( executablePath , $ "-config { skudefPath } ") ;
98
+ Process . Start ( startInfo ) ;
99
+ }
100
+ // TODO: 与Launch合并
101
+
67
102
public void Register ( )
68
103
{
69
- //ToDo : 需要直接写入,而不是依赖RA3.reg
70
- try
104
+ if ( IsRA3PathValid ( ) && Registry . Status != Registry . RegistryStatus . Correct )
71
105
{
72
- if ( File . Exists ( "RA3.reg" ) )
73
- {
74
- string regPath = Path . GetFullPath ( "RA3.reg" ) ;
75
- regPath = @"""" + regPath + @"""" ;
76
- Process . Start ( "regedit" , string . Format ( " /s {0}" , regPath ) ) ;
77
- }
78
- //write registion here.
106
+ Registry . SetRA3Path ( GamePath ) ;
107
+ Registry . EnableMapSync ( ) ;
79
108
}
80
- catch ( Exception ) { }
81
109
}
82
110
83
111
public void Launch ( )
@@ -100,7 +128,7 @@ public void Launch()
100
128
#endregion
101
129
102
130
#region Steam & Origin Version detection.
103
- //From @BSG-75 (https://github.com/BSG-75 )
131
+ //From @lanyizi (https://github.com/lanyizi )
104
132
public bool DoesRA3NeedSteamAppID ( )
105
133
{
106
134
var ra3Path = GamePath ;
@@ -132,7 +160,7 @@ public void GenerateSteamAppID()
132
160
}
133
161
134
162
//Abandoned
135
- public void GeneratePatchedParFile ( )
163
+ public void _GeneratePatchedParFile ( )
136
164
{
137
165
var tucParPath = Path . Combine ( GamePath , "Data" , "ra3_1.12.par" ) ;
138
166
var oldFileId = 0 ;
@@ -147,7 +175,11 @@ public void GeneratePatchedParFile()
147
175
#endregion
148
176
149
177
#region Profile Operations
150
- // Parse string encoded by EA similar to UTF-8 in directory.ini
178
+ /// <summary>
179
+ /// Parse string encoded by EA similar to UTF-8 in directory.ini
180
+ /// </summary>
181
+ /// <param name="s">string</param>
182
+ /// <returns></returns>
151
183
private string ParseDirectoryString ( string s )
152
184
{
153
185
var bytes = new List < byte > ( ) ;
@@ -168,7 +200,10 @@ private string ParseDirectoryString(string s)
168
200
}
169
201
return Encoding . Unicode . GetString ( bytes . ToArray ( ) ) ;
170
202
}
171
-
203
+ /// <summary>
204
+ /// Get list of avaliable profiles list.
205
+ /// </summary>
206
+ /// <returns>List of avaliable game profiles.</returns>
172
207
private List < string > GetProfilesList ( )
173
208
{
174
209
var original = ParseDirectoryString ( File . ReadAllLines ( $ "{ ProfileFolder . Path } \\ directory.ini") [ 0 ] ) ;
@@ -216,7 +251,7 @@ public void DeleteAllSkirmishINI()
216
251
}
217
252
#endregion
218
253
219
- //ToDo:1.完善检测文件完整的函数
220
- //ToDo:8.软链接修改Mod,Map,Replay的位置(在ResourceFolder类中)
254
+ //ToDo: 1.完善检测文件完整的函数
255
+ //ToDo: 8.软链接修改Mod,Map,Replay的位置(在ResourceFolder类中)
221
256
}
222
257
}
0 commit comments