mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Merge pull request #334 from solacens/globalization/support-intl-version-game-launching
[Globalization] Support intl version game launching
This commit is contained in:
@@ -36,7 +36,16 @@ internal class GachaLogUrlWebCacheProvider : IGachaLogUrlProvider
|
||||
public static string GetCacheFile(string path)
|
||||
{
|
||||
string folder = Path.GetDirectoryName(path) ?? string.Empty;
|
||||
return Path.Combine(folder, @"YuanShen_Data\webCaches\Cache\Cache_Data\data_2");
|
||||
var cacheDataPath = Path.Combine(folder, @"YuanShen_Data\webCaches\Cache\Cache_Data\data_2");
|
||||
var cacheDataPathIntl = Path.Combine(folder, @"GenshinImpact_Data\webCaches\Cache\Cache_Data\data_2");
|
||||
if (File.Exists(cacheDataPath))
|
||||
{
|
||||
return cacheDataPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cacheDataPathIntl;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -207,7 +207,7 @@ internal class GameService : IGameService, IDisposable
|
||||
return true;
|
||||
}
|
||||
|
||||
return Process.GetProcessesByName("YuanShen.exe").Any();
|
||||
return Process.GetProcessesByName("YuanShen.exe").Any() || Process.GetProcessesByName("GenshinImpact.exe").Any();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -30,18 +30,26 @@ internal class ManualGameLocator : IGameLocator
|
||||
/// <inheritdoc/>
|
||||
public Task<ValueResult<bool, string>> LocateGamePathAsync()
|
||||
{
|
||||
return LocateInternalAsync("YuanShen.exe");
|
||||
List<string> filenames = new List<string>()
|
||||
{
|
||||
"YuanShen.exe",
|
||||
"GenshinImpact.exe",
|
||||
};
|
||||
return LocateInternalAsync(filenames);
|
||||
}
|
||||
|
||||
private async Task<ValueResult<bool, string>> LocateInternalAsync(string fileName)
|
||||
private async Task<ValueResult<bool, string>> LocateInternalAsync(List<string> fileNames)
|
||||
{
|
||||
FileOpenPicker picker = pickerFactory.GetFileOpenPicker(PickerLocationId.Desktop, "选择游戏本体", ".exe");
|
||||
if (await picker.PickSingleFileAsync() is StorageFile file)
|
||||
{
|
||||
string path = file.Path;
|
||||
if (path.Contains(fileName))
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
return new(true, path);
|
||||
if (path.Contains(fileName))
|
||||
{
|
||||
return new(true, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,28 +22,48 @@ internal partial class UnityLogGameLocator : IGameLocator
|
||||
await ThreadHelper.SwitchToBackgroundAsync();
|
||||
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
string logFilePath = Path.Combine(appDataPath, @"..\LocalLow\miHoYo\原神\output_log.txt");
|
||||
string logFilePathIntl = Path.Combine(appDataPath, @"..\LocalLow\miHoYo\Genshin Impact\output_log.txt");
|
||||
|
||||
using (TempFile? tempFile = TempFile.CreateFromFileCopy(logFilePath))
|
||||
using (TempFile? tempFile = TempFile.CreateFromFileCopy(logFilePath), tempFileIntl = TempFile.CreateFromFileCopy(logFilePathIntl))
|
||||
{
|
||||
if (tempFile == null)
|
||||
if (tempFile != null)
|
||||
{
|
||||
return new(false, $"找不到 Unity 日志文件:\n{logFilePath}");
|
||||
string content = File.ReadAllText(tempFile.Path);
|
||||
|
||||
Match matchResult = WarmupFileLine().Match(content);
|
||||
if (!matchResult.Success)
|
||||
{
|
||||
return new(false, $"在 Unity 日志文件中找不到游戏路径");
|
||||
}
|
||||
|
||||
string entryName = matchResult.Groups[0].Value.Replace("_Data", ".exe");
|
||||
string fullPath = Path.GetFullPath(Path.Combine(matchResult.Value, "..", entryName));
|
||||
return new(true, fullPath);
|
||||
}
|
||||
|
||||
string content = File.ReadAllText(tempFile.Path);
|
||||
|
||||
Match matchResult = WarmupFileLine().Match(content);
|
||||
if (!matchResult.Success)
|
||||
else if (tempFileIntl != null)
|
||||
{
|
||||
return new(false, $"在 Unity 日志文件中找不到游戏路径");
|
||||
}
|
||||
string content = File.ReadAllText(tempFileIntl.Path);
|
||||
|
||||
string entryName = matchResult.Groups[0].Value.Replace("_Data", ".exe");
|
||||
string fullPath = Path.GetFullPath(Path.Combine(matchResult.Value, "..", entryName));
|
||||
return new(true, fullPath);
|
||||
Match matchResult = WarmupFileLineIntl().Match(content);
|
||||
if (!matchResult.Success)
|
||||
{
|
||||
return new(false, $"在 Unity 日志文件中找不到游戏路径");
|
||||
}
|
||||
|
||||
string entryName = matchResult.Groups[0].Value.Replace("_Data", ".exe");
|
||||
string fullPath = Path.GetFullPath(Path.Combine(matchResult.Value, "..", entryName));
|
||||
return new(true, fullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new(false, $"找不到 Unity 日志文件:\n{logFilePath}\n{logFilePathIntl}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"(?m).:/.+YuanShen_Data")]
|
||||
private static partial Regex WarmupFileLine();
|
||||
|
||||
[GeneratedRegex(@"(?m).:/.+GenshinImpact_Data")]
|
||||
private static partial Regex WarmupFileLineIntl();
|
||||
}
|
||||
Reference in New Issue
Block a user