Skip to content

Commit 59e22b8

Browse files
Initial PupNet test
1 parent a358f75 commit 59e22b8

File tree

7 files changed

+147
-6
lines changed

7 files changed

+147
-6
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
if: ${{ github.event_name != 'pull_request' }}
3434
with:
3535
path: "Deploy/OUT/MSUScripter*"
36-
name: MSUScripterLinux
36+
name: MSUScripter
3737

3838
# - name: Restore dependencies
3939
# run: dotnet restore

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: .NET Build + Publish
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [main, ui-rewrite]
66
pull_request:
77
branches: [main]
88

@@ -47,4 +47,4 @@ jobs:
4747
if: ${{ github.event_name != 'pull_request' }}
4848
with:
4949
path: "setup/Output/*"
50-
name: MSUScripter_${{ steps.version.outputs.number }}
50+
name: MSUScripter

MSUScripter/Assets/app.metainfo.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
<keyword>development</keyword>
2929
<keyword>programming</keyword>
3030
</keywords>
31-
31+
<!--
3232
<screenshots>
3333
<screenshot type="default">
34-
<image>https://private-user-images.githubusercontent.com/63823784/356325792-a31f393d-7b62-4550-b475-c754404332bd.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTg1NDgzMzMsIm5iZiI6MTc1ODU0ODAzMywicGF0aCI6Ii82MzgyMzc4NC8zNTYzMjU3OTItYTMxZjM5M2QtN2I2Mi00NTUwLWI0NzUtYzc1NDQwNDMzMmJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA5MjIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwOTIyVDEzMzM1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEzZjI5ZDc5ZThmMjExZDc3OTIwOGMwYTUyNDA3M2Y4MzUzYjU4YTUxMzliYzQzYjYzOWQyNzVkZDZjNTU2MzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KO9do_00DMvZSFlkft31g9sVz25VfRG9e0pk_UcNrpU</image>
34+
<image></image>
3535
</screenshot>
36-
</screenshots>
36+
</screenshots> -->
3737

3838
<releases>
3939
${APPSTREAM_CHANGELOG_XML}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Name=MSU Scripter
4+
Icon=org.mattequalscoder.msuscripter
5+
StartupWMClass=MSUScripter
6+
Comment=UI application for creating MSUs and PCM files
7+
Exec=%FileName%
8+
TryExec=%FileName%
9+
NoDisplay=false
10+
Terminal=false
11+
Categories=Utility;
12+
X-AppImage-Name=AppId
13+
X-AppImage-Version=AppVersion
14+
X-AppImage-Arch=PackageArch
15+
MimeType=
16+
Keywords=
17+
Icon=%IconPath%
18+
Path=%FolderPath%
19+
Actions=remove
20+
21+
[Desktop Action remove]
22+
Name=Uninstall MSU Scripter
23+
Exec=%UninstallPath%

MSUScripter/Assets/uninstall.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
rm -f "%IconPath%"
4+
rm -f "%FolderPath%/%FileName%"
5+
rm -f "%DesktopFilePath%"
6+
rm -rf "%LocalDataPath%"

MSUScripter/MSUScripter.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050

5151
<ItemGroup>
5252
<AvaloniaResource Include="Assets\**" />
53+
<EmbeddedResource Include="Assets\icon.svg" />
54+
<EmbeddedResource Include="Assets\org.mattequalscoder.msuscripter.desktop" />
55+
<EmbeddedResource Include="Assets\uninstall.sh" />
5356
<EmbeddedResource Include="empty.pcm" />
5457
</ItemGroup>
5558

MSUScripter/Program.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Reflection;
56
// ReSharper disable once RedundantUsingDirective
67
using System.Linq;
78
using System.Threading;
@@ -61,6 +62,11 @@ public static void Main(string[] args)
6162
{
6263
StartingProject = args[0];
6364
}
65+
66+
if (OperatingSystem.IsLinux())
67+
{
68+
_ = SetupLinuxDesktopFile();
69+
}
6470

6571
MainHost = Host.CreateDefaultBuilder(args)
6672
.UseSerilog()
@@ -161,6 +167,109 @@ await Dispatcher.UIThread.Invoke(async () =>
161167
});
162168
}
163169

170+
private static async Task SetupLinuxDesktopFile()
171+
{
172+
await Task.Run(() =>
173+
{
174+
var desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
175+
"applications");
176+
if (!Directory.Exists(desktopPath))
177+
{
178+
return;
179+
}
180+
181+
var iconFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
182+
"icons");
183+
if (!Directory.Exists(iconFolderPath))
184+
{
185+
Directory.CreateDirectory(iconFolderPath);
186+
}
187+
188+
var iconPath = Path.Combine(Path.Combine(iconFolderPath, "MSUScripter.svg"));
189+
190+
var appImagePath = Directory.EnumerateFiles(Environment.CurrentDirectory, "MSUScripter*.AppImage")
191+
.FirstOrDefault();
192+
Log.Logger.Information("appImagePath: {Path}", appImagePath);
193+
if (string.IsNullOrEmpty(appImagePath) || !File.Exists(appImagePath))
194+
{
195+
return;
196+
}
197+
198+
var desktopFilePath = Path.Combine(desktopPath, "MSUScripter.desktop");
199+
var uninstallFilePath = Path.Combine(Directories.BaseFolder, "uninstall.sh");
200+
201+
var assembly = Assembly.GetExecutingAssembly();
202+
CopyIconFile(assembly, iconPath);
203+
CopyUninstallFile(assembly, appImagePath, iconPath, desktopFilePath, uninstallFilePath);
204+
CopyDesktopFile(assembly, appImagePath, iconPath, uninstallFilePath, desktopFilePath);
205+
});
206+
}
207+
208+
private static void CopyDesktopFile(Assembly assembly, string appImagePath, string iconPath, string uninstallPath, string targetPath)
209+
{
210+
const string resourceName = "MSUScripter.Assets.org.mattequalscoder.msuscripter.desktop";
211+
using var stream = assembly.GetManifestResourceStream(resourceName);
212+
if (stream == null)
213+
{
214+
return;
215+
}
216+
using var reader = new StreamReader(stream);
217+
var desktopText = reader.ReadToEnd();
218+
219+
var workingDirectory = Path.GetDirectoryName(appImagePath);
220+
var fileName = Path.GetFileName(appImagePath);
221+
desktopText = desktopText.Replace("%FolderPath%", workingDirectory);
222+
desktopText = desktopText.Replace("%FileName%", fileName);
223+
desktopText = desktopText.Replace("%IconPath%", iconPath);
224+
desktopText = desktopText.Replace("%DesktopFilePath%", targetPath);
225+
desktopText = desktopText.Replace("%UninstallPath%", uninstallPath);
226+
File.WriteAllText(targetPath, desktopText);
227+
}
228+
229+
private static void CopyUninstallFile(Assembly assembly, string appImagePath, string iconPath, string desktopFilePath, string targetPath)
230+
{
231+
if (!OperatingSystem.IsLinux())
232+
{
233+
return;
234+
}
235+
236+
const string resourceName = "MSUScripter.Assets.uninstall.sh";
237+
using var stream = assembly.GetManifestResourceStream(resourceName);
238+
if (stream == null)
239+
{
240+
return;
241+
}
242+
using var reader = new StreamReader(stream);
243+
var fileText = reader.ReadToEnd();
244+
245+
var workingDirectory = Path.GetDirectoryName(appImagePath);
246+
var fileName = Path.GetFileName(appImagePath);
247+
fileText = fileText.Replace("%FolderPath%", workingDirectory);
248+
fileText = fileText.Replace("%FileName%", fileName);
249+
fileText = fileText.Replace("%IconPath%", iconPath);
250+
fileText = fileText.Replace("%DesktopFilePath%", desktopFilePath);
251+
fileText = fileText.Replace("%LocalDataPath%", Directories.BaseFolder);
252+
File.WriteAllText(targetPath, fileText);
253+
File.SetUnixFileMode(targetPath, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute | UnixFileMode.GroupExecute);
254+
}
255+
256+
private static void CopyIconFile(Assembly assembly, string targetPath)
257+
{
258+
const string resourceName = "MSUScripter.Assets.icon.svg";
259+
using var stream = assembly.GetManifestResourceStream(resourceName);
260+
if (stream == null)
261+
{
262+
return;
263+
}
264+
265+
using var fileStream = new FileStream(Path.Combine(targetPath), FileMode.Create);
266+
for (var i = 0; i < stream.Length; i++)
267+
{
268+
fileStream.WriteByte((byte)stream.ReadByte());
269+
}
270+
fileStream.Close();
271+
}
272+
164273
#if DEBUG
165274
private static string LogPath => Path.Combine(Directories.LogFolder, "msu-scripter-debug_.log");
166275
#else

0 commit comments

Comments
 (0)