Skip to content

Commit d3d1dc1

Browse files
committed
up
1 parent 28d176f commit d3d1dc1

28 files changed

Lines changed: 142 additions & 171 deletions

build/build-macos.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ build_osx()
3535
mkdir $base/ColorMC.app
3636
mkdir $base_dir
3737

38-
files=("ColorMC.Gui.pdb" "ColorMC.Core.pdb" "ColorMC.Launcher" "ColorMC.Launcher.pdb"
39-
"libAvaloniaNative.dylib" "libHarfBuzzSharp.dylib" "libSkiaSharp.dylib"
40-
"libSDL2-2.0.dylib" "MinecraftSkinRender.OpenGL.pdb" "MinecraftSkinRender.pdb")
38+
files=("ColorMC.Launcher" "libAvaloniaNative.dylib" "libHarfBuzzSharp.dylib" "libSkiaSharp.dylib" "libSDL2-2.0.dylib")
4139

4240
cp -r ./build/info/osx/* $base_dir
4341

@@ -53,13 +51,13 @@ build_osx()
5351

5452
chmod a+x $dir/ColorMC.Launcher
5553

56-
if [$1 = 'aarch64'] && [replace_sdl = 'true'] ;then
54+
if [$1 = 'aarch64'] && [$replace_sdl = 'true'] ;then
5755
build_sdl_arm64
5856
fi
5957

6058
cd ./src/build_out/$1-dotnet
6159

62-
if [$1 = 'aarch64'] && [replace_sdl = 'true'] ;then
60+
if [$1 = 'aarch64'] && [$replace_sdl = 'true'] ;then
6361
rm libSDL2-2.0.dylib
6462
cp ../../../SDL/build/build/.libs/libSDL2-2.0.0.dylib libSDL2-2.0.dylib
6563
fi
@@ -88,8 +86,7 @@ build_osx_min()
8886
mkdir $base/ColorMC.app
8987
mkdir $base_dir
9088

91-
files=("ColorMC.Launcher" "libAvaloniaNative.dylib" "libHarfBuzzSharp.dylib" "libSkiaSharp.dylib"
92-
"libSDL2-2.0.dylib")
89+
files=("ColorMC.Launcher" "libAvaloniaNative.dylib" "libHarfBuzzSharp.dylib" "libSkiaSharp.dylib" "libSDL2-2.0.dylib")
9390

9491
cp -r ./build/info/osx/* $base_dir
9592

@@ -105,17 +102,18 @@ build_osx_min()
105102

106103
chmod a+x $dir/ColorMC.Launcher
107104

108-
if [$1 = 'aarch64'] && [replace_sdl = 'true'] ;then
105+
if [$1 = 'aarch64'] && [$replace_sdl = 'true'] ;then
109106
build_sdl_arm64
110107
fi
111108

112109
cd ./src/build_out/$1-min
113110

114-
if [$1 = 'aarch64'] && [replace_sdl = 'true'] ;then
111+
if [$1 = 'aarch64'] && [$replace_sdl = 'true'] ;then
115112
rm libSDL2-2.0.dylib
116113
cp ../../../SDL/build/build/.libs/libSDL2-2.0.0.dylib libSDL2-2.0.dylib
117114
fi
118115

116+
codesign --force --deep --sign - ColorMC.app
119117
zip -r $zip_name ./ColorMC.app
120118
mv $zip_name ../../../build_out/$zip_name
121119
cd ../../../

src/ColorMC.Core/Helpers/CheckHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static bool CheckAllow(List<GameArgObj.GameLibrariesObj.GameRulesObj> lis
6868
}
6969
var os = item2.Os.Name;
7070

71-
if (os == "osx" && SystemInfo.Os == OsType.MacOS)
71+
if (os == "osx" && SystemInfo.Os == OsType.MacOs)
7272
{
7373
allow = true;
7474
}
@@ -100,7 +100,7 @@ public static bool CheckAllow(List<GameArgObj.GameLibrariesObj.GameRulesObj> lis
100100
}
101101
var os = item2.Os.Name;
102102

103-
if (os == "osx" && SystemInfo.Os == OsType.MacOS)
103+
if (os == "osx" && SystemInfo.Os == OsType.MacOs)
104104
{
105105
allow = false;
106106
}

src/ColorMC.Core/Helpers/GameDownloadHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public static async Task<ConcurrentBag<FileItemObj>> BuildGameLibsAsync(this Gam
473473
{
474474
OsType.Windows => item1.Downloads.Classifiers.NativesWindows,
475475
OsType.Linux => item1.Downloads.Classifiers.NativesLinux,
476-
OsType.MacOS => item1.Downloads.Classifiers.NativesOsx,
476+
OsType.MacOs => item1.Downloads.Classifiers.NativesOsx,
477477
_ => null
478478
};
479479

@@ -567,7 +567,7 @@ public static async Task<ConcurrentBag<FileItemObj>> BuildGameLibsAsync(this Gam
567567
string system = SystemInfo.Os switch
568568
{
569569
OsType.Linux => "linux",
570-
OsType.MacOS => "macos",
570+
OsType.MacOs => "macos",
571571
_ => "windows"
572572
};
573573
var name = item + $":{path[1]}-{path[2]}-natives-{system}-arm64";

src/ColorMC.Core/Helpers/PathHelper.cs

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -105,66 +105,72 @@ public static Task<bool> MoveToTrashAsync(string dir)
105105
{
106106
try
107107
{
108-
if (SystemInfo.Os == OsType.Windows)
108+
switch (SystemInfo.Os)
109109
{
110-
return Win32.MoveToTrash(dir);
111-
}
112-
else if (SystemInfo.Os == OsType.Linux)
113-
{
114-
string trashFilesPath = GetTrashFilesPath();
115-
string trashInfoPath = GetTrashInfoPath();
116-
117-
string fileName = Path.GetFileName(dir);
118-
string destPath = Path.Combine(trashFilesPath, fileName);
119-
string trashInfoFile = Path.Combine(trashInfoPath, fileName + ".trashinfo");
120-
121-
// 处理文件名冲突
122-
int counter = 1;
123-
while (File.Exists(destPath) || Directory.Exists(destPath))
110+
case OsType.Windows:
111+
return Win32.MoveToTrash(dir);
112+
case OsType.Linux:
124113
{
125-
string nameWithoutExt = Path.GetFileNameWithoutExtension(fileName);
126-
string ext = Path.GetExtension(fileName);
127-
destPath = Path.Combine(trashFilesPath, $"{nameWithoutExt}_{counter}{ext}");
128-
trashInfoFile = Path.Combine(trashInfoPath, $"{nameWithoutExt}_{counter}{ext}.trashinfo");
129-
counter++;
114+
string trashFilesPath = GetTrashFilesPath();
115+
string trashInfoPath = GetTrashInfoPath();
116+
117+
string fileName = Path.GetFileName(dir);
118+
string destPath = Path.Combine(trashFilesPath, fileName);
119+
string trashInfoFile = Path.Combine(trashInfoPath, fileName + ".trashinfo");
120+
121+
// 处理文件名冲突
122+
int counter = 1;
123+
while (File.Exists(destPath) || Directory.Exists(destPath))
124+
{
125+
string nameWithoutExt = Path.GetFileNameWithoutExtension(fileName);
126+
string ext = Path.GetExtension(fileName);
127+
destPath = Path.Combine(trashFilesPath, $"{nameWithoutExt}_{counter}{ext}");
128+
trashInfoFile = Path.Combine(trashInfoPath, $"{nameWithoutExt}_{counter}{ext}.trashinfo");
129+
counter++;
130+
}
131+
132+
// 创建 .trashinfo 文件
133+
string trashInfoContent = GenerateTrashInfoContent(dir, DateTime.Now);
134+
File.WriteAllText(trashInfoFile, trashInfoContent);
135+
136+
if (File.Exists(dir))
137+
{
138+
File.Move(dir, destPath);
139+
}
140+
else if (Directory.Exists(dir))
141+
{
142+
Directory.Move(dir, destPath);
143+
}
144+
145+
return true;
130146
}
131-
132-
// 创建 .trashinfo 文件
133-
string trashInfoContent = GenerateTrashInfoContent(dir, DateTime.Now);
134-
File.WriteAllText(trashInfoFile, trashInfoContent);
135-
136-
if (File.Exists(dir))
147+
case OsType.MacOs:
137148
{
138-
File.Move(dir, destPath);
149+
dir = dir.Replace("\\", @"\\")
150+
.Replace("\"", "\\\"")
151+
.Replace("\n", "\\n")
152+
.Replace("\r", "\\r")
153+
.Replace("\t", "\\t");
154+
155+
// AppleScript命令
156+
string appleScriptCommand = $"tell application \"Finder\" to delete POSIX file \"{dir}\"";
157+
158+
// 使用bash执行AppleScript
159+
var processInfo = new ProcessStartInfo("osascript", ["-e", appleScriptCommand])
160+
{
161+
RedirectStandardOutput = true,
162+
RedirectStandardError = true,
163+
CreateNoWindow = true
164+
};
165+
166+
using var process = new Process { StartInfo = processInfo };
167+
process.Start();
168+
string output = process.StandardOutput.ReadToEnd();
169+
string error = process.StandardError.ReadToEnd();
170+
process.WaitForExit();
171+
172+
return process.ExitCode == 0;
139173
}
140-
else if (Directory.Exists(dir))
141-
{
142-
Directory.Move(dir, destPath);
143-
}
144-
145-
return true;
146-
}
147-
else if (SystemInfo.Os == OsType.MacOS)
148-
{
149-
// AppleScript命令
150-
string appleScriptCommand = $"tell application \"Finder\" to delete POSIX file \"{dir}\"";
151-
152-
// 使用bash执行AppleScript
153-
var processInfo = new ProcessStartInfo("bash", $"-c \"osascript -e '{appleScriptCommand}'\"")
154-
{
155-
RedirectStandardOutput = true,
156-
RedirectStandardError = true,
157-
UseShellExecute = false,
158-
CreateNoWindow = true
159-
};
160-
161-
using var process = new Process { StartInfo = processInfo };
162-
process.Start();
163-
string output = process.StandardOutput.ReadToEnd();
164-
string error = process.StandardError.ReadToEnd();
165-
process.WaitForExit();
166-
167-
return process.ExitCode == 0;
168174
}
169175
}
170176
catch

src/ColorMC.Core/LaunchPath/InnerPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class InnerPath
1010
static InnerPath()
1111
{
1212
//存在用户文件夹
13-
Inner = SystemInfo.Os == OsType.MacOS ?
13+
Inner = SystemInfo.Os == OsType.MacOs ?
1414
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ColorMC") :
1515
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ColorMC");
1616
if (!Directory.Exists(Inner))

src/ColorMC.Core/LaunchPath/JvmPath.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static async Task<StringRes> DownloadAsync(string name, string sha256, s
129129
return SystemInfo.Os switch
130130
{
131131
OsType.Windows => PathHelper.GetFile(path, Names.NameJavawFile),
132-
OsType.Linux or OsType.MacOS => PathHelper.GetFile(path, Names.NameJavaFile),
132+
OsType.Linux or OsType.MacOs => PathHelper.GetFile(path, Names.NameJavaFile),
133133
_ => null,
134134
};
135135
}
@@ -172,7 +172,7 @@ public static async Task<BaseRes> UnzipJavaAsync(string name, string file, IZipG
172172
}
173173
}
174174

175-
if (SystemInfo.Os is OsType.Linux or OsType.MacOS)
175+
if (SystemInfo.Os is OsType.Linux or OsType.MacOs)
176176
{
177177
PathHelper.PerJavaChmod(java);
178178
}

src/ColorMC.Core/Objs/Enums.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,7 @@ public enum OsType
415415
{
416416
Windows,
417417
Linux,
418-
MacOS,
419-
Android,
420-
Ios
418+
MacOs,
421419
}
422420

423421
/// <summary>

src/ColorMC.Core/Utils/ProcessUtils.cs

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,7 @@ public static bool IsRunAsAdmin()
2626
else
2727
{
2828
// 检查当前用户是否是 root
29-
if (Environment.UserName.Equals("root", StringComparison.OrdinalIgnoreCase))
30-
{
31-
return true;
32-
}
33-
return false;
34-
35-
// 检查当前用户是否属于 sudo 组
36-
//var process = new Process
37-
//{
38-
// StartInfo = new ProcessStartInfo
39-
// {
40-
// FileName = "groups",
41-
// RedirectStandardOutput = true,
42-
// UseShellExecute = false,
43-
// CreateNoWindow = true
44-
// }
45-
//};
46-
47-
//process.Start();
48-
//string output = process.StandardOutput.ReadToEnd();
49-
//process.WaitForExit();
50-
51-
//return output.Contains("sudo");
29+
return Environment.UserName.Equals("root", StringComparison.OrdinalIgnoreCase);
5230
}
5331
}
5432

@@ -62,21 +40,23 @@ public static bool Launch(Process process, bool admin)
6240
if (admin && !IsRunAsAdmin())
6341
{
6442
process.StartInfo.UseShellExecute = true;
65-
if (SystemInfo.Os == OsType.Windows)
43+
switch (SystemInfo.Os)
6644
{
67-
process.StartInfo.Verb = "runas";
68-
}
69-
else if (SystemInfo.Os == OsType.MacOS)
70-
{
71-
var list = new List<string>(process.StartInfo.ArgumentList);
72-
list.Insert(0, process.StartInfo.FileName);
73-
process.StartInfo.FileName = "sudo";
74-
}
75-
else
76-
{
77-
var list = new List<string>(process.StartInfo.ArgumentList);
78-
list.Insert(0, process.StartInfo.FileName);
79-
process.StartInfo.FileName = "pkexec";
45+
case OsType.Windows:
46+
process.StartInfo.Verb = "runas";
47+
break;
48+
case OsType.MacOs:
49+
{
50+
process.StartInfo.ArgumentList.Insert(0, process.StartInfo.FileName);
51+
process.StartInfo.FileName = "sudo";
52+
break;
53+
}
54+
case OsType.Linux:
55+
{
56+
process.StartInfo.ArgumentList.Insert(0, process.StartInfo.FileName);
57+
process.StartInfo.FileName = "pkexec";
58+
break;
59+
}
8060
}
8161

8262
process.StartInfo.RedirectStandardInput = false;
@@ -106,10 +86,11 @@ public static void LaunchAdmin(string[] args)
10686
p.StartInfo.FileName = file;
10787
p.StartInfo.UseShellExecute = true;
10888
}
109-
else if (SystemInfo.Os == OsType.MacOS)
89+
else if (SystemInfo.Os == OsType.MacOs)
11090
{
111-
p.StartInfo.ArgumentList.Add(file);
112-
p.StartInfo.FileName = "sudo";
91+
p.StartInfo.ArgumentList.Add("-e");
92+
p.StartInfo.ArgumentList.Add($"do shell script \"{file}\" with administrator privileges");
93+
p.StartInfo.FileName = "osascript";
11394
p.StartInfo.UseShellExecute = true;
11495
}
11596
else
@@ -124,5 +105,6 @@ public static void LaunchAdmin(string[] args)
124105
}
125106

126107
p.Start();
108+
p.WaitForExit();
127109
}
128110
}

src/ColorMC.Core/Utils/SystemInfo.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,7 @@ public static void Init()
7878
}
7979
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
8080
{
81-
Os = OsType.MacOS;
82-
}
83-
84-
if (OperatingSystem.IsAndroid())
85-
{
86-
Os = OsType.Android;
87-
}
88-
else if (OperatingSystem.IsIOS())
89-
{
90-
Os = OsType.Ios;
81+
Os = OsType.MacOs;
9182
}
9283

9384
SystemName = RuntimeInformation.OSDescription;

src/ColorMC.Gui/ColorMCGui.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static void Main(string[] args)
126126
try
127127
{
128128
ProcessUtils.LaunchAdmin(args);
129+
App.Close();
129130
}
130131
catch
131132
{
@@ -456,7 +457,7 @@ public static AppBuilder BuildAvaloniaApp()
456457
builder.With(opt);
457458
break;
458459
}
459-
case OsType.MacOS:
460+
case OsType.MacOs:
460461
{
461462
var opt = new MacOSPlatformOptions()
462463
{

0 commit comments

Comments
 (0)