Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build output
bin/
obj/

# User-specific files
*.user
*.suo
.vs/

# NuGet
*.nupkg
packages/

# Publish output
publish/
23 changes: 0 additions & 23 deletions UpdateService/App.config

This file was deleted.

2 changes: 1 addition & 1 deletion UpdateService/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void LoadSettings()
try
{
var json = File.ReadAllText(AppSettingsPath);
var doc = JsonDocument.Parse(json);
using var doc = JsonDocument.Parse(json);

if (doc.RootElement.TryGetProperty("DestinationFilePath", out var dest))
TxtDestinationFilePath.Text = dest.GetString() ?? string.Empty;
Expand Down
27 changes: 14 additions & 13 deletions UpdateService/UpdateService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;

namespace UpdateService
{
Expand Down Expand Up @@ -40,7 +39,6 @@ public async Task ExecuteAsync()
/// </summary>
private async Task ExecuteServiceAsync()
{
const string pattern = @".+\\";
var folderNames = GetFolderName(_serviceFilePath);

if (folderNames.Count == 0)
Expand Down Expand Up @@ -68,16 +66,16 @@ private async Task ExecuteServiceAsync()
switch (_executeMode)
{
case ExecuteModeEnum.Complete:
await UnInstallAsync(unInstalls, pattern, destinationFilePath, folderName);
await UnInstallAsync(unInstalls, destinationFilePath, folderName);
OverWriteDestinationFile(destinationFilePath, serviceFilePath, folderName);
await InstallAsync(installs, pattern, destinationFilePath, folderName);
await InstallAsync(installs, destinationFilePath, folderName);
break;
case ExecuteModeEnum.UnInstall:
await UnInstallAsync(unInstalls, pattern, destinationFilePath, folderName);
await UnInstallAsync(unInstalls, destinationFilePath, folderName);
break;
case ExecuteModeEnum.Install:
OverWriteDestinationFile(destinationFilePath, serviceFilePath, folderName);
await InstallAsync(installs, pattern, destinationFilePath, folderName);
await InstallAsync(installs, destinationFilePath, folderName);
break;
default:
_log("錯誤資訊:請確認安裝模式是否設定正確");
Expand Down Expand Up @@ -122,21 +120,19 @@ private async Task ExecuteProcessAsync(string workingDirectory, string fileName)
/// <summary>
/// 執行安裝流程
/// </summary>
private async Task InstallAsync(string[] installs, string pattern, string destinationFilePath, string folderName)
private async Task InstallAsync(string[] installs, string destinationFilePath, string folderName)
{
var match = Regex.Match(installs[0], pattern);
var batFile = installs[0].Replace(match.Value, "");
var batFile = Path.GetFileName(installs[0]);
_log($"開始執行 安裝 {folderName} 服務");
await ExecuteProcessAsync(destinationFilePath, batFile);
}

/// <summary>
/// 執行解除安裝流程
/// </summary>
private async Task UnInstallAsync(string[] unInstalls, string pattern, string destinationFilePath, string folderName)
private async Task UnInstallAsync(string[] unInstalls, string destinationFilePath, string folderName)
{
var match = Regex.Match(unInstalls[0], pattern);
var batFile = unInstalls[0].Replace(match.Value, "");
var batFile = Path.GetFileName(unInstalls[0]);
_log($"開始執行 解除安裝 {folderName} 服務");
await ExecuteProcessAsync(destinationFilePath, batFile);
}
Expand Down Expand Up @@ -166,10 +162,12 @@ private void OverWriteDestinationFile(string destinationFilePath, string service
catch (UnauthorizedAccessException)
{
_log($"錯誤資訊:覆寫 {folderName} 資料夾權限不足");
throw;
}
catch (DirectoryNotFoundException e)
{
_log($"錯誤資訊:{e.Message} 檔案遺失");
throw;
}
}

Expand All @@ -183,7 +181,10 @@ private static List<string> GetFolderName(string filePath)
if (directories.Length == 0)
return names;

names.AddRange(directories.Select(Path.GetFileNameWithoutExtension).Where(n => n != null)!);
names.AddRange(directories
.Select(Path.GetFileNameWithoutExtension)
.Where(n => !string.IsNullOrEmpty(n))
.Select(n => n!));
return names;
}
}
Expand Down
21 changes: 0 additions & 21 deletions UpdateService/bin/Debug/UpdateService.application

This file was deleted.

Binary file removed UpdateService/bin/Debug/UpdateService.exe
Binary file not shown.
23 changes: 0 additions & 23 deletions UpdateService/bin/Debug/UpdateService.exe.config

This file was deleted.

65 changes: 0 additions & 65 deletions UpdateService/bin/Debug/UpdateService.exe.manifest

This file was deleted.

Binary file removed UpdateService/bin/Debug/UpdateService.pdb
Binary file not shown.
Binary file not shown.
Binary file removed UpdateService/bin/Debug/net8.0-windows/UpdateService
Binary file not shown.
23 changes: 0 additions & 23 deletions UpdateService/bin/Debug/net8.0-windows/UpdateService.deps.json

This file was deleted.

Binary file not shown.
23 changes: 0 additions & 23 deletions UpdateService/bin/Debug/net8.0-windows/UpdateService.dll.config

This file was deleted.

Binary file not shown.

This file was deleted.

4 changes: 0 additions & 4 deletions UpdateService/bin/Debug/net8.0-windows/appsettings.json

This file was deleted.

21 changes: 0 additions & 21 deletions UpdateService/bin/Release/UpdateService.application

This file was deleted.

Binary file removed UpdateService/bin/Release/UpdateService.exe
Binary file not shown.
23 changes: 0 additions & 23 deletions UpdateService/bin/Release/UpdateService.exe.config

This file was deleted.

Loading