Skip to content

Commit

Permalink
[+] Write example config when config not found
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Sep 16, 2024
1 parent e557f13 commit 85493cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions AquaMai/AquaMai.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="AquaMai.zh.toml" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="AquaMai.toml" />
<EmbeddedResource Include="AquaMai.zh.toml" WithCulture="false" />
<EmbeddedResource Include="AquaMai.toml" />
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml" />
Expand Down
25 changes: 20 additions & 5 deletions AquaMai/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using AquaMai.Fix;
using AquaMai.Helpers;
Expand Down Expand Up @@ -79,6 +80,13 @@ private void ApplyPatches()
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleOutputCP(uint wCodePageID);

private void WriteEmbeddedResourceToFile(string resource, string file)
{
using var s = MelonAssembly.Assembly.GetManifestResourceStream(resource);
using var fs = File.Open(file, FileMode.Create);
s.CopyTo(fs);
}

public override void OnInitializeMelon()
{
// Prevent Chinese characters from being garbled
Expand All @@ -87,14 +95,21 @@ public override void OnInitializeMelon()
MelonLogger.Msg("Loading mod settings...");

// Check if AquaMai.toml exists
if (!System.IO.File.Exists("AquaMai.toml"))
if (!File.Exists("AquaMai.toml"))
{
WriteEmbeddedResourceToFile("AquaMai.AquaMai.toml", "AquaMai.example.toml");
WriteEmbeddedResourceToFile("AquaMai.AquaMai.zh.toml", "AquaMai.example.zh.toml");
MelonLogger.Error("======================================!!!");
MelonLogger.Error("AquaMai.toml not found! Please create it.");
MelonLogger.Error("找不到配置文件 AquaMai.toml!请创建。");
MelonLogger.Error("Example copied to AquaMai.example.toml");
MelonLogger.Error("示例已复制到 AquaMai.example.zh.toml");
MelonLogger.Error("=========================================");
return;
}

// Read AquaMai.toml to load settings
AppConfig = TomletMain.To<Config>(System.IO.File.ReadAllText("AquaMai.toml"));
AppConfig = TomletMain.To<Config>(File.ReadAllText("AquaMai.toml"));

// Migrate old settings
AppConfig.UX.LoadAssetsPng = AppConfig.UX.LoadAssetsPng || AppConfig.UX.LoadJacketPng;
Expand Down Expand Up @@ -123,17 +138,17 @@ public override void OnInitializeMelon()

if (_hasErrors)
{
MelonLogger.Warning("!!!!!=================================================================!!!!!");
MelonLogger.Warning("========================================================================!!!");
MelonLogger.Warning("加载过程中检测到错误!");
MelonLogger.Warning("- 请检查你是否安装了错误的 AquaMai 版本,比如在 SDGA 上使用了 SDEZ 的版本");
MelonLogger.Warning("- 你是否正在使用魔改的 Assembly-CSharp.dll,这会导致函数不一致而无法找到需要修改的函数");
MelonLogger.Warning("- 请检查是否有冲突的 Mod,或者开启了不兼容的选项");
MelonLogger.Warning("!!!!!=================================================================!!!!!");
MelonLogger.Warning("===========================================================================");
MelonLogger.Warning("Errors detected while loading!");
MelonLogger.Warning("- Check if you have installed the wrong version of AquaMai, such as using SDEZ version on SDGA");
MelonLogger.Warning("- Are you using a modified Assembly-CSharp.dll, which will cause inconsistent functions and cannot find the functions that need to be modified");
MelonLogger.Warning("- Check for conflicting mods, or enabled incompatible options");
MelonLogger.Warning("!!!!!=================================================================!!!!!");
MelonLogger.Warning("===========================================================================");
}

MelonLogger.Msg("Loaded!");
Expand Down

0 comments on commit 85493cd

Please sign in to comment.