diff --git a/.gitignore b/.gitignore index 9b364dd..c497c96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,10 @@ bin obj .vs +*.user *.dll + +# Build results +Properties/ +.vs/ +.obj/ diff --git a/CanaryLauncher.csproj b/CanaryLauncher.csproj new file mode 100644 index 0000000..e1d5a5f --- /dev/null +++ b/CanaryLauncher.csproj @@ -0,0 +1,97 @@ + + + + + Debug + AnyCPU + {E21D451C-4724-4738-A716-DD441AD38747} + WinExe + CanaryLauncher + icon.ico + CanaryLauncher + v4.8 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + + + + + + + + + + + + + + + diff --git a/CanaryLauncher.sln b/CanaryLauncher.sln new file mode 100644 index 0000000..74d1c05 --- /dev/null +++ b/CanaryLauncher.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33205.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CanaryLauncher", "CanaryLauncher.csproj", "{E21D451C-4724-4738-A716-DD441AD38747}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E21D451C-4724-4738-A716-DD441AD38747}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E21D451C-4724-4738-A716-DD441AD38747}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E21D451C-4724-4738-A716-DD441AD38747}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E21D451C-4724-4738-A716-DD441AD38747}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F0CE66E6-7311-4CFA-8866-0B11975F833A} + EndGlobalSection +EndGlobal diff --git a/CanaryLauncherUpdate.csproj b/CanaryLauncherUpdate.csproj deleted file mode 100644 index 086b88b..0000000 --- a/CanaryLauncherUpdate.csproj +++ /dev/null @@ -1,92 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - true - launcher_ico.png - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - True - \ - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - - - - - - True - \ - - - - - - PreserveNewest - - - - diff --git a/CanaryLauncherUpdate.csproj.user b/CanaryLauncherUpdate.csproj.user deleted file mode 100644 index e9fcd01..0000000 --- a/CanaryLauncherUpdate.csproj.user +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - Designer - - - - - Code - - - - - Designer - - - Designer - - - \ No newline at end of file diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs deleted file mode 100644 index 1a1548d..0000000 --- a/MainWindow.xaml.cs +++ /dev/null @@ -1,268 +0,0 @@ -using System; -using System.Windows; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.IO; -using System.IO.Compression; -using System.Net; -using System.Diagnostics; -using Newtonsoft.Json; -using System.Net.Http; - -namespace CanaryLauncherUpdate -{ - - public partial class MainWindow : Window - { - HttpClient httpClient = new HttpClient(); - WebClient webClient = new WebClient(); - - bool clientDownloaded = false; - bool needUpdate = false; - string clientName = "client.exe"; - string urlClient = "https://github.com/lucasgiovannibr/clientlauncherupdate/archive/refs/heads/main.zip"; - string urlVersion = "https://raw.githubusercontent.com/lucasgiovannibr/clientlauncherupdate/main/version.txt"; - string currentVersion = ""; - string path = AppDomain.CurrentDomain.BaseDirectory.ToString(); - - public MainWindow() - { - InitializeComponent(); - } - - private void TibiaLauncher_Load(object sender, RoutedEventArgs e) - { - ImageLogoServer.Source = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/logo.png")); - ImageLogoCompany.Source = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/logo_company.png")); - - currentVersion = httpClient.GetStringAsync(urlVersion).Result; - progressbarDownload.Visibility = Visibility.Collapsed; - labelClientVersion.Visibility = Visibility.Collapsed; - labelDownloadPercent.Visibility = Visibility.Collapsed; - - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - if (Directory.Exists(path + "/clientlauncherupdate-main")) - { - clientDownloaded = true; - } - - if (File.Exists(path + "/clientlauncherupdate-main/version.txt")) - { - StreamReader reader = new StreamReader(path + "/clientlauncherupdate-main/version.txt"); - string? myVersion = reader.ReadLine(); - reader.Close(); - - labelVersion.Text = "v" + currentVersion; - - if (currentVersion == myVersion) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_play.png"))); - buttonPlayIcon.Source = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/icon_play.png")); - labelClientVersion.Content = GetClientVersion(path); - labelClientVersion.Visibility = Visibility.Visible; - buttonPlay_tooltip.Text = "Play Game"; - needUpdate = false; - } - - if (currentVersion != myVersion) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_update.png"))); - buttonPlayIcon.Source = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/icon_update.png")); - labelClientVersion.Content = "Download"; - labelClientVersion.Visibility = Visibility.Visible; - buttonPlay.Visibility = Visibility.Visible; - buttonPlay_tooltip.Text = "Update"; - needUpdate = true; - } - } - if (!File.Exists(path + "/clientlauncherupdate-main/version.txt")) - { - labelVersion.Text = "v" + currentVersion; - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_update.png"))); - buttonPlayIcon.Source = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/icon_update.png")); - labelClientVersion.Content = "Download"; - labelClientVersion.Visibility = Visibility.Visible; - buttonPlay.Visibility = Visibility.Visible; - buttonPlay_tooltip.Text = "Download"; - needUpdate = true; - } - } - - static string GetClientVersion(string path) - { - string json = path + "/clientlauncherupdate-main/package.json"; - StreamReader stream = new StreamReader(json); - dynamic jsonString = stream.ReadToEnd(); - dynamic versionclient = JsonConvert.DeserializeObject(jsonString); - foreach (string version in versionclient) - { - return version; - } - return "Play Game"; - } - - private void buttonPlay_Click(object sender, RoutedEventArgs e) - { - if (needUpdate == true) - { - try - { - labelDownloadPercent.Visibility = Visibility.Visible; - progressbarDownload.Visibility = Visibility.Visible; - labelClientVersion.Visibility = Visibility.Collapsed; - buttonPlay.Visibility = Visibility.Collapsed; - webClient.DownloadProgressChanged += Client_DownloadProgressChanged; - webClient.DownloadFileCompleted += Client_DownloadFileCompleted; - webClient.DownloadFileAsync(new Uri(urlClient), path + "/tibia.zip"); - } - catch (Exception ex) - { - labelVersion.Text = ex.ToString(); - } - } - else - { - if (clientDownloaded == true) - { - Process.Start(path + "/clientlauncherupdate-main/bin/" + clientName); - this.Close(); - } - else - { - try - { - labelDownloadPercent.Visibility = Visibility.Visible; - progressbarDownload.Visibility = Visibility.Visible; - labelClientVersion.Visibility = Visibility.Collapsed; - buttonPlay.Visibility = Visibility.Collapsed; - webClient.DownloadProgressChanged += Client_DownloadProgressChanged; - webClient.DownloadFileCompleted += Client_DownloadFileCompleted; - webClient.DownloadFileAsync(new Uri(urlClient), path + "/tibia.zip"); - } - catch (Exception ex) - { - labelVersion.Text = ex.ToString(); - } - } - } - } - - private void Client_DownloadFileCompleted(object? sender, System.ComponentModel.AsyncCompletedEventArgs e) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_play.png"))); - buttonPlayIcon.Source = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/icon_play.png")); - - Directory.CreateDirectory(path); - ZipFile.ExtractToDirectory(path + "/tibia.zip", path, true); - File.Delete(path + "/tibia.zip"); - progressbarDownload.Value = 100; - needUpdate = false; - clientDownloaded = true; - labelClientVersion.Content = "Play Game"; - buttonPlay_tooltip.Text = "Play Game"; - labelClientVersion.Visibility = Visibility.Visible; - buttonPlay.Visibility = Visibility.Visible; - progressbarDownload.Visibility = Visibility.Collapsed; - labelDownloadPercent.Visibility = Visibility.Collapsed; - } - - private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - progressbarDownload.Value = e.ProgressPercentage; - labelDownloadPercent.Content = SizeSuffix(e.BytesReceived) + " / " + SizeSuffix(e.TotalBytesToReceive); - } - - static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; - static string SizeSuffix(Int64 value, int decimalPlaces = 1) - { - if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException("decimalPlaces"); } - if (value < 0) { return "-" + SizeSuffix(-value, decimalPlaces); } - if (value == 0) { return string.Format("{0:n" + decimalPlaces + "} bytes", 0); } - - int mag = (int)Math.Log(value, 1024); - decimal adjustedSize = (decimal)value / (1L << (mag * 10)); - - if (Math.Round(adjustedSize, decimalPlaces) >= 1000) - { - mag += 1; - adjustedSize /= 1024; - } - return string.Format("{0:n" + decimalPlaces + "} {1}", - adjustedSize, - SizeSuffixes[mag]); - } - - private void buttonPlay_MouseEnter(object sender, MouseEventArgs e) - { - if (File.Exists(path + "/clientlauncherupdate-main/version.txt")) - { - StreamReader reader = new StreamReader(path + "/clientlauncherupdate-main/version.txt"); - string? myVersion = reader.ReadLine(); - reader.Close(); - - if (currentVersion != myVersion) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_hover_update.png"))); - } - if (currentVersion == myVersion) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_hover_play.png"))); - } - } - else - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_hover_update.png"))); - } - } - - private void buttonPlay_MouseLeave(object sender, MouseEventArgs e) - { - if (File.Exists(path + "/clientlauncherupdate-main/version.txt")) - { - StreamReader reader = new StreamReader(path + "/clientlauncherupdate-main/version.txt"); - string? myVersion = reader.ReadLine(); - reader.Close(); - - if (currentVersion != myVersion) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_update.png"))); - } - if (currentVersion == myVersion) - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_play.png"))); - } - } - else - { - buttonPlay.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "Assets/button_update.png"))); - } - } - - private void CloseButton_Click(object sender, RoutedEventArgs e) - { - Close(); - } - - private void RestoreButton_Click(object sender, RoutedEventArgs e) - { - if (ResizeMode != ResizeMode.NoResize) - { - if (WindowState == WindowState.Normal) - WindowState = WindowState.Maximized; - else - WindowState = WindowState.Normal; - } - } - - private void MinimizeButton_Click(object sender, RoutedEventArgs e) - { - WindowState = WindowState.Minimized; - } - - } -} diff --git a/Properties/PublishProfiles/FolderProfile.pubxml b/Properties/PublishProfiles/FolderProfile.pubxml deleted file mode 100644 index 4ac9958..0000000 --- a/Properties/PublishProfiles/FolderProfile.pubxml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - Release - Any CPU - bin\Release\net6.0-windows\publish\ - FileSystem - - \ No newline at end of file diff --git a/Properties/PublishProfiles/FolderProfile.pubxml.user b/Properties/PublishProfiles/FolderProfile.pubxml.user deleted file mode 100644 index 10965bb..0000000 --- a/Properties/PublishProfiles/FolderProfile.pubxml.user +++ /dev/null @@ -1,9 +0,0 @@ - - - - - True|2022-10-07T16:56:25.9223960Z;True|2022-10-07T13:54:42.8724885-03:00;True|2022-10-07T13:16:26.4419014-03:00; - - \ No newline at end of file diff --git a/SplashScreen.xaml.cs b/SplashScreen.xaml.cs deleted file mode 100644 index 44a3e93..0000000 --- a/SplashScreen.xaml.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Windows; -using System.IO; -using System.Net; -using System.Windows.Threading; -using System.Net.Http; - -namespace CanaryLauncherUpdate -{ - public partial class SplashScreen : Window - { - static readonly HttpClient httpClient = new HttpClient(); - DispatcherTimer timer = new DispatcherTimer(); - string urlClient = "https://github.com/lucasgiovannibr/clientlauncherupdate/archive/refs/heads/main.zip"; - string urlVersion = "https://raw.githubusercontent.com/lucasgiovannibr/clientlauncherupdate/main/version.txt"; - string currentVersion = ""; - string path = AppDomain.CurrentDomain.BaseDirectory.ToString(); - - public SplashScreen() - { - InitializeComponent(); - timer.Tick += new EventHandler(timer_SplashScreen); - timer.Interval = new TimeSpan(0, 0, 5); - timer.Start(); - } - - public async void timer_SplashScreen(object? sender, EventArgs e) - { - var requestCurrentVersion = new HttpRequestMessage(HttpMethod.Post, urlVersion); - var responseCurrentVersion = await httpClient.SendAsync(requestCurrentVersion); - currentVersion = await responseCurrentVersion.Content.ReadAsStringAsync(); - if (currentVersion == null) - { - this.Close(); - } - - var requestClient = new HttpRequestMessage(HttpMethod.Post, urlClient); - var response = await httpClient.SendAsync(requestClient); - if (response.StatusCode == HttpStatusCode.NotFound) - { - this.Close(); - } - - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - MainWindow mainWindow = new MainWindow(); - this.Close(); - mainWindow.Show(); - timer.Stop(); - } - } -} diff --git a/Assets/launcher_ico.ico b/icon.ico similarity index 100% rename from Assets/launcher_ico.ico rename to icon.ico diff --git a/launcher_config.json b/launcher_config.json new file mode 100644 index 0000000..105badb --- /dev/null +++ b/launcher_config.json @@ -0,0 +1,29 @@ +/** +• JSON configuration file for the Client Updater +• version The version of the client, represented as "major.minor.patch". +• replaceFolders Whether the updater should replace the client's current folders +• folders An array of objects representing the client's folders, each object has the key "name" +• clientFolder The name of the main client folder, represented as "Tibia" +NOTE: Set it to "false" or only "" to not use the client folder, so everything will be added to the main folder +• newClientUrl The URL where the new client version can be downloaded from +• executable The path to the client's executable file, represented as "bin/molten.exe" +*/ +{ + "clientVersion": "12.91.12329", + "launcherVersion": "1.0", + "replaceFolders": false, + "replaceFolderName": [ + { + "name": "assets" + }, + { + "name": "storeimages" + }, + { + "name": "bin" + } + ], + "clientFolder": "Tibia", + "newClientUrl" : "https://github.com/dudantas/CanaryLauncherUpdate/releases/download/download-files/client-to-update.zip", + "clientExecutable": "client.exe" +} diff --git a/App.xaml b/src/App.xaml similarity index 96% rename from App.xaml rename to src/App.xaml index 7012581..da27899 100644 --- a/App.xaml +++ b/src/App.xaml @@ -7,7 +7,7 @@ - + - -