-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
206 lines (173 loc) · 6.42 KB
/
Copy pathProgram.cs
File metadata and controls
206 lines (173 loc) · 6.42 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
string? providedGameDirectory = null;
string? providedOutputDirectory = null;
foreach (var arg in args)
{
if (arg.StartsWith("--game-dir="))
{
providedGameDirectory = arg.Replace("--game-dir=", "");
}
else if (arg.StartsWith("--output-dir="))
{
providedOutputDirectory = arg.Replace("--output-dir=", "");
}
}
var eveOnlineGameDirectory = ResolveGameDirectory(providedGameDirectory);
if (eveOnlineGameDirectory == null)
{
Console.WriteLine("Could not find an EVE installation. Use --game-dir to set it explicitly.");
return;
}
if (!TryResolveInstallLayout(eveOnlineGameDirectory, out var resourceFile, out var resourceFilePrefetch, out var eveOnlineResourceDirectory))
{
Console.WriteLine("Could not find required EVE resource indexes. Use --game-dir to set it explicitly.");
return;
}
var outputDirectory = ResolveOutputDirectory(providedOutputDirectory);
// create the output directory
Directory.CreateDirectory(outputDirectory);
List<ResourceRow> rows = [];
Console.WriteLine("EVE Online Asset Extractor");
Console.WriteLine($"Version: {Assembly.GetExecutingAssembly().GetName().Version}");
Console.WriteLine("Created by EVE Workbench");
Console.WriteLine("---");
// Read all lines from the CSV file
rows.AddRange(ReadLines(resourceFile));
rows.AddRange(ReadLines(resourceFilePrefetch));
foreach (var image in rows)
{
var mediaType = GetMediaType(image.FileName);
if (mediaType == null) continue;
var mediaOutputDirectory = Path.Combine(outputDirectory, mediaType);
Directory.CreateDirectory(mediaOutputDirectory);
var sourceFile = Path.Combine(eveOnlineResourceDirectory, image.Path.Replace('/', Path.DirectorySeparatorChar));
if (File.Exists(sourceFile))
{
var outputFileName = image.FileName
.Replace("res:/", string.Empty, StringComparison.OrdinalIgnoreCase)
.Replace("/", "_")
.Replace("\\", "_");
var outputFile = Path.Combine(mediaOutputDirectory, outputFileName);
File.Copy(sourceFile, outputFile, true);
Console.WriteLine($"Copies {sourceFile} to {outputFile}");
}
}
List<ResourceRow> ReadLines(string file)
{
var lines = File.ReadAllLines(file);
return lines.Select(line => line.Split(',')).Select(values => new ResourceRow { FileName = values[0], Path = values[1] }).ToList();
}
string? GetMediaType(string fileName)
{
if (fileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
fileName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))
{
return "image";
}
if (fileName.EndsWith(".webm", StringComparison.OrdinalIgnoreCase) ||
fileName.EndsWith(".srt", StringComparison.OrdinalIgnoreCase))
{
return "video";
}
return null;
}
string ResolveOutputDirectory(string? cliOutputDirectory)
{
if (!string.IsNullOrWhiteSpace(cliOutputDirectory))
{
return cliOutputDirectory;
}
// Place extracted assets next to the executable when no output path is provided.
return Path.Combine(AppContext.BaseDirectory, "assets");
}
string? ResolveGameDirectory(string? cliGameDirectory)
{
if (!string.IsNullOrWhiteSpace(cliGameDirectory))
{
return cliGameDirectory;
}
var candidates = GetCandidateGameDirectories();
foreach (var candidate in candidates.Where(c => !string.IsNullOrWhiteSpace(c)).Distinct())
{
if (HasRequiredEveFiles(candidate))
{
return candidate;
}
}
return null;
}
IEnumerable<string> GetCandidateGameDirectories()
{
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var candidates = new List<string>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
candidates.Add(Path.Combine("C:", "CCP", "EVE"));
candidates.Add(Path.Combine("D:", "CCP", "EVE"));
candidates.Add(Path.Combine("E:", "CCP", "EVE"));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
candidates.Add(Path.Combine(home, "Library", "Application Support", "EVE Online", "SharedCache"));
candidates.Add(Path.Combine(home, "Library", "Application Support", "CCP", "EVE", "SharedCache"));
candidates.Add(Path.Combine(home, "Library", "Application Support", "Steam", "steamapps", "compatdata", "8500", "pfx", "drive_c", "CCP", "EVE"));
candidates.Add(Path.Combine(home, ".steam", "steam", "steamapps", "compatdata", "8500", "pfx", "drive_c", "CCP", "EVE"));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
candidates.Add(Path.Combine(home, ".steam", "steam", "steamapps", "compatdata", "8500", "pfx", "drive_c", "CCP", "EVE"));
candidates.Add(Path.Combine(home, ".local", "share", "Steam", "steamapps", "compatdata", "8500", "pfx", "drive_c", "CCP", "EVE"));
}
return candidates;
}
bool HasRequiredEveFiles(string gameDirectory)
{
return TryResolveInstallLayout(gameDirectory, out _, out _, out _);
}
bool TryResolveInstallLayout(
string gameDirectory,
out string indexFile,
out string prefetchFile,
out string resFilesDirectory)
{
indexFile = string.Empty;
prefetchFile = string.Empty;
resFilesDirectory = string.Empty;
if (!Directory.Exists(gameDirectory))
{
return false;
}
resFilesDirectory = Path.Combine(gameDirectory, "ResFiles");
if (!Directory.Exists(resFilesDirectory))
{
return false;
}
var standardIndex = Path.Combine(gameDirectory, "tq", "resfileindex.txt");
var standardPrefetch = Path.Combine(gameDirectory, "tq", "resfileindex_prefetch.txt");
if (File.Exists(standardIndex) && File.Exists(standardPrefetch))
{
indexFile = standardIndex;
prefetchFile = standardPrefetch;
return true;
}
var macIndex = Path.Combine(gameDirectory, "tq", "EVE.app", "Contents", "Resources", "build", "resfileindex.txt");
var macPrefetch = Path.Combine(gameDirectory, "tq", "EVE.app", "Contents", "Resources", "build", "resfileindex_prefetch.txt");
if (File.Exists(macIndex) && File.Exists(macPrefetch))
{
indexFile = macIndex;
prefetchFile = macPrefetch;
return true;
}
return false;
}
internal record ResourceRow
{
public required string FileName { get; set; }
public required string Path { get; set; }
}