-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
444 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
|
||
namespace osu_launcher.Classes | ||
{ | ||
internal class Helper | ||
{ | ||
public static async Task<string> GetVersion(string currentVersion) | ||
{ | ||
try | ||
{ | ||
var releaseType = currentVersion.Split('-')[1]; | ||
var githubClient = new GitHubClient(new ProductHeaderValue("osu-Launcher")); | ||
var tags = await githubClient.Repository.GetAllTags("puk06", "osu-Launcher"); | ||
string latestVersion = currentVersion; | ||
foreach (var tag in tags) | ||
{ | ||
if (releaseType == "Release") | ||
{ | ||
if (tag.Name.Split('-')[1] != "Release") continue; | ||
latestVersion = tag.Name; | ||
break; | ||
} | ||
|
||
latestVersion = tag.Name; | ||
break; | ||
} | ||
|
||
return latestVersion; | ||
} | ||
catch | ||
{ | ||
throw new Exception("アップデートの取得に失敗しました"); | ||
} | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.IO.Compression; | ||
using System.Net; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace osu_launcher.Updater.Classes | ||
{ | ||
public class Updater | ||
{ | ||
private readonly string _version; | ||
|
||
public Updater(string version) | ||
{ | ||
_version = version; | ||
} | ||
|
||
private const string Baseurl = "https://github.com/puk06/osu-Launcher/releases/download/"; | ||
|
||
public async Task Update() | ||
{ | ||
var downloadUrl = $"{Baseurl}{_version}/osu-Launcher.zip"; | ||
var tempPath = Path.GetTempPath(); | ||
var tempFile = Path.Combine(tempPath, $"osu-Launcher.zip"); | ||
var extractPath = Path.Combine(tempPath, $"osu-Launcher.Temp"); | ||
|
||
Console.WriteLine("ファイルのダウンロードを開始しています..."); | ||
Console.WriteLine("ファイルのダウンロード中です...ソフトを終了しないでください!"); | ||
|
||
using var client = new WebClient(); | ||
await client.DownloadFileTaskAsync(new Uri(downloadUrl), tempFile); | ||
|
||
Console.WriteLine("ダウンロードが完了しました!"); | ||
Console.WriteLine("ファイルの展開中です..."); | ||
|
||
ZipFile.ExtractToDirectory(tempFile, extractPath, Encoding.UTF8, true); | ||
File.Delete(tempFile); | ||
|
||
var folders = Directory.GetDirectories(extractPath); | ||
folders = folders.Where(x => !x.Contains("Updater")).ToArray(); | ||
var files = Directory.GetFiles(extractPath); | ||
|
||
var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
if (currentPath == null) | ||
{ | ||
Console.WriteLine("カレントフォルダの取得に失敗しました。"); | ||
Thread.Sleep(3000); | ||
return; | ||
} | ||
var softwarePath = Directory.GetParent(currentPath)?.FullName; | ||
if (softwarePath == null) | ||
{ | ||
Console.WriteLine("ソフトウェアのフォルダの取得に失敗しました。"); | ||
Thread.Sleep(3000); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < files.Length; i++) | ||
{ | ||
var file = files[i]; | ||
var fileName = Path.GetFileName(file); | ||
var currentFile = Path.Combine(softwarePath, fileName); | ||
Console.WriteLine($"ファイルのコピー中です... {i + 1}/{files.Length}: {fileName}"); | ||
File.Copy(file, currentFile, true); | ||
} | ||
|
||
for (int i = 0; i < folders.Length; i++) | ||
{ | ||
var folder = folders[i]; | ||
var folderName = Path.GetFileName(folder); | ||
var currentFolder = Path.Combine(softwarePath, folderName); | ||
if (!Directory.Exists(currentFolder)) Directory.CreateDirectory(currentFolder); | ||
Console.WriteLine($"フォルダのコピー中です... {i + 1}/{folders.Length}: {folderName}"); | ||
DirectoryCopy(folder, currentFolder, true); | ||
} | ||
|
||
Directory.Delete(extractPath, true); | ||
} | ||
|
||
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) | ||
{ | ||
var dir = new DirectoryInfo(sourceDirName); | ||
var dirs = dir.GetDirectories(); | ||
|
||
if (!dir.Exists) throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName); | ||
if (!Directory.Exists(destDirName)) Directory.CreateDirectory(destDirName); | ||
|
||
|
||
var files = dir.GetFiles(); | ||
foreach (var file in files) | ||
{ | ||
var tempPath = Path.Combine(destDirName, file.Name); | ||
if (file.Name == "data.json") continue; | ||
file.CopyTo(tempPath, true); | ||
} | ||
|
||
if (!copySubDirs) return; | ||
foreach (var subdir in dirs) | ||
{ | ||
var tempPath = Path.Combine(destDirName, subdir.Name); | ||
DirectoryCopy(subdir.FullName, tempPath, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Diagnostics; | ||
using Octokit; | ||
|
||
namespace osu_launcher.Updater | ||
{ | ||
internal class Program | ||
{ | ||
private static async Task Main(string[] args) | ||
{ | ||
try | ||
{ | ||
if (args.Length != 1) | ||
{ | ||
Console.WriteLine("バージョン情報が取得できませんでした。ソフト内から実行するようにしてください!"); | ||
Thread.Sleep(3000); | ||
return; | ||
} | ||
|
||
var currentVersion = args[0]; | ||
|
||
if (string.IsNullOrEmpty(currentVersion)) | ||
{ | ||
Console.WriteLine("バージョン情報が取得できませんでした。ソフト内から実行するようにしてください!"); | ||
Thread.Sleep(3000); | ||
return; | ||
} | ||
|
||
Console.WriteLine("アップデートを確認します。"); | ||
|
||
var latestVersion = await GithubUpdateChecker(currentVersion); | ||
|
||
if (latestVersion == currentVersion) | ||
{ | ||
Console.WriteLine("最新バージョンです!ソフトを使ってくれてありがとうございます!"); | ||
Thread.Sleep(3000); | ||
return; | ||
} | ||
|
||
Console.WriteLine($"最新バージョンが見つかりました({currentVersion} → {latestVersion})"); | ||
Console.ReadLine(); | ||
Console.WriteLine("osu-Launcher関係のソフトをすべて終了します。"); | ||
|
||
var processes = Process.GetProcessesByName("osu-launcher"); | ||
foreach (var process in processes) | ||
{ | ||
process.Kill(); | ||
} | ||
|
||
Console.WriteLine("osu-Launcherを終了しました。アップデートを開始します。"); | ||
var updater = new Classes.Updater(latestVersion); | ||
|
||
await updater.Update(); | ||
|
||
Console.WriteLine("アップデートが完了しました!ソフトを使ってくれてありがとうございます!"); | ||
Thread.Sleep(3000); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine("アップデート中にエラーが発生しました: " + e.Message); | ||
Thread.Sleep(3000); | ||
} | ||
} | ||
|
||
private static async Task<string> GithubUpdateChecker(string currentVersion) | ||
{ | ||
var latestRelease = await GetVersion(currentVersion); | ||
return latestRelease == currentVersion ? currentVersion : latestRelease; | ||
} | ||
|
||
private static async Task<string> GetVersion(string currentVersion) | ||
{ | ||
var releaseType = currentVersion.Split('-')[1]; | ||
var githubClient = new GitHubClient(new ProductHeaderValue("osu-Launcher")); | ||
var tags = await githubClient.Repository.GetAllTags("puk06", "osu-Launcher"); | ||
string latestVersion = currentVersion; | ||
foreach (var tag in tags) | ||
{ | ||
if (releaseType == "Release") | ||
{ | ||
if (tag.Name.Split("-")[1] != "Release") continue; | ||
latestVersion = tag.Name; | ||
break; | ||
} | ||
|
||
latestVersion = tag.Name; | ||
break; | ||
} | ||
|
||
return latestVersion; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>osu_launcher.Updater</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Octokit" Version="13.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.