diff --git a/ClientHandler/Program.cs b/ClientHandler/Program.cs
index 5f0e241e..e6b33ae4 100644
--- a/ClientHandler/Program.cs
+++ b/ClientHandler/Program.cs
@@ -160,4 +160,4 @@ public Task WaitForExitTaskAsync()
});
}
}
-}
+}
\ No newline at end of file
diff --git a/Package/Package.appxmanifest b/Package/Package.appxmanifest
index 259f8673..01e49313 100644
--- a/Package/Package.appxmanifest
+++ b/Package/Package.appxmanifest
@@ -11,7 +11,7 @@
+ Version="0.4.5.0" />
SD Launcher
diff --git a/SDLauncher UWP/Dialogs/Login.xaml.cs b/SDLauncher UWP/Dialogs/Login.xaml.cs
index e2d4fecd..5741476d 100644
--- a/SDLauncher UWP/Dialogs/Login.xaml.cs
+++ b/SDLauncher UWP/Dialogs/Login.xaml.cs
@@ -342,15 +342,6 @@ private void UpdateAccounts()
}
private void btnChooseAcc_Click(object sender, RoutedEventArgs e)
{
- for (int i = vars.Accounts.Count - 1; i >= 0; i--)
- {
- try
- {
- vars.Accounts[i].PropertyChanged -= Login_PropertyChanged;
- }
- catch { }
- vars.Accounts[i].PropertyChanged += Login_PropertyChanged;
- }
ShowSelect(false, false);
gridChoose.Visibility = Visibility.Visible;
gridNew.Visibility = Visibility.Collapsed;
@@ -358,10 +349,6 @@ private void btnChooseAcc_Click(object sender, RoutedEventArgs e)
UpdateAccounts();
}
- private void Login_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- // UpdateAccounts();
- }
private void btnBack_Click(object sender, RoutedEventArgs e)
{
diff --git a/SDLauncher UWP/Helpers/Labrinth.cs b/SDLauncher UWP/Helpers/Labrinth.cs
index 62887dec..7c22a0a1 100644
--- a/SDLauncher UWP/Helpers/Labrinth.cs
+++ b/SDLauncher UWP/Helpers/Labrinth.cs
@@ -7,6 +7,10 @@
using System.Text;
using System.Threading.Tasks;
using System.Web;
+using Windows.Foundation;
+using Windows.Networking.BackgroundTransfer;
+using Windows.Storage;
+using Windows.UI.Xaml;
namespace SDLauncher_UWP.Helpers
{
@@ -25,6 +29,8 @@ public class Labrinth
{
public event EventHandler StatusChanged = delegate { };
public event EventHandler UIChangeRequested = delegate { };
+ public event EventHandler MainUIChangeRequested = delegate { };
+ public event EventHandler ProgressChanged = delegate { };
public HttpClient Client = new HttpClient();
//ModrinthClient c = new ModrinthClient();
public void Test()
@@ -38,19 +44,96 @@ private void UI(bool UI)
{
UIChangeRequested(this, new SDLauncher.UIChangeRequestedEventArgs(UI));
}
- public async Task Search(string name, int? limit = null)
+ int DownloadTaskID;
+ public async void DownloadMod(LabrinthResults.DownloadManager.File file,CmlLib.Core.MinecraftPath mcPath)
+ {
+ DownloadTaskID = LittleHelp.AddTask("Download " + file.filename);
+ MainUIChangeRequested(this, new SDLauncher.UIChangeRequestedEventArgs(false));
+ StorageFolder f = await StorageFolder.GetFolderFromPathAsync(mcPath.BasePath);
+ var m = await f.CreateFolderAsync("mods", CreationCollisionOption.OpenIfExists);
+ try
+ {
+ var mfile = await m.CreateFileAsync(file.filename, CreationCollisionOption.FailIfExists);
+ await mfile.DeleteAsync();
+ ModrinthDownload(file.url, mcPath.BasePath + @"\mods\", file.filename);
+ }
+ catch
+ {
+ var r = await MessageBox.Show("Information", "The file \"" + file.filename + "\" already exists in the mod folder.\nDo you want to download and replace it ?", MessageBoxButtons.YesNo);
+ if (r == MessageBoxResults.Yes)
+ {
+ ModrinthDownload(file.url, m.Path, file.filename);
+ }
+ else
+ {
+ this.MainUIChangeRequested(this, new SDLauncher.UIChangeRequestedEventArgs(true));
+ LittleHelp.CompleteTask(DownloadTaskID);
+ }
+ }
+ }
+ private async void ModrinthDownload(string link,string folderdir, string fileName)
+ {
+ try
+ {
+ Uri source = new Uri(link);
+
+ var folder = await StorageFolder.GetFolderFromPathAsync(folderdir);
+ var file = await folder.CreateFileAsync(
+ fileName,
+ CreationCollisionOption.ReplaceExisting);
+ string path = file.Path;
+ file = null;
+ using (var client = new HttpClientDownloadWithProgress(link, path))
+ {
+ client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => {
+ StatusChanged("Download " + fileName, new EventArgs());
+ this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: Convert.ToInt32(progressPercentage)));
+ if(progressPercentage == 100)
+ {
+ this.DownloadFileCompleted();
+ client.Dispose();
+ }
+ };
+
+ await client.StartDownload();
+ }
+
+ }
+ catch
+ {
+
+ }
+ }
+ private void DownloadFileCompleted()
+ {
+ StatusChanged("Ready", new EventArgs());
+ ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg:0));
+ LittleHelp.CompleteTask(DownloadTaskID);
+ MainUIChangeRequested(this, new SDLauncher.UIChangeRequestedEventArgs(true));
+ }
+ public async Task Search(string name, int? limit = null, LabrinthResults.SearchSortOptions sortOptions = LabrinthResults.SearchSortOptions.Relevance, LabrinthResults.SearchCategories[] categories = null)
{
int taskID = 0;
UI(false);
if (name == "")
{
StatusChanged("Getting Mods",new EventArgs());
- taskID = LittleHelp.AddTask("Getting Mods");
+ taskID = LittleHelp.AddTask("Get Mods");
}
else
{
- taskID = LittleHelp.AddTask("Searcging Store");
- StatusChanged("Searcging Store", new EventArgs());
+ taskID = LittleHelp.AddTask("Search Store");
+ StatusChanged("Searching Store", new EventArgs());
+ }
+ string categouriesString = "";
+ if(categories != null)
+ {
+ if (categories.Count() > 0)
+ {
+ categouriesString = string.Join("\"],[\"categories:", categories);
+ categouriesString = ",[\"categories:" + categouriesString + "\"]";
+ categouriesString = categouriesString.ToLower();
+ }
}
LabrinthResults.SearchResult s = null;
try
@@ -65,7 +148,7 @@ private void UI(bool UI)
{
l = "limit=";
}
- var json = await Util.DownloadText("https://api.modrinth.com/v2/search?query=" + q + "&facets=[[%22categories:fabric%22],[%22project_type:mod%22]]&" + l);
+ var json = await Util.DownloadText("https://api.modrinth.com/v2/search?query=" + q + "&index=" + sortOptions.ToString().ToLower() + "&facets=[[\"categories:fabric\"]" + categouriesString + ",[\"project_type:mod\"]]&" + l);
s = JSONConverter.ConvertToLabrinthSearchResult(json);
StatusChanged("Ready", new EventArgs());
UI(true);
@@ -80,10 +163,13 @@ private void UI(bool UI)
return null;
}
}
- public async Task GetProject(string id)
+ public async Task GetProject(string id,bool UIChange = true)
{
- int taskID = LittleHelp.AddTask("Loading Mod");
- UI(false);
+ int taskID = LittleHelp.AddTask("Load Mod");
+ if (UIChange)
+ {
+ UI(false);
+ }
StatusChanged("Loading Mod",new EventArgs());
LabrinthResults.ModrinthProject s = null;
try
@@ -91,6 +177,36 @@ private void UI(bool UI)
var json = await Util.DownloadText("https://api.modrinth.com/v2/project/" + id);
s = JSONConverter.ConvertToLabrinthProject(json);
StatusChanged("Ready", new EventArgs());
+ if (UIChange)
+ {
+ UI(true);
+ }
+ LittleHelp.CompleteTask(taskID);
+ return s;
+ }
+ catch
+ {
+ StatusChanged("Ready", new EventArgs());
+ if (UIChange)
+ {
+ UI(true);
+ }
+ LittleHelp.CompleteTask(taskID);
+ return null;
+ }
+ }
+ public async Task> GetVersions(string id)
+ {
+ int taskID = LittleHelp.AddTask("Load Download versionss");
+ UI(false);
+ StatusChanged("Loading Mod downloads", new EventArgs());
+ List s = null;
+ try
+ {
+ string link = "https://api.modrinth.com/v2/project/" + id + "/version";
+ var json = await Util.DownloadText(link);
+ s = JSONConverter.ConvertDownloadLinksToCS(json);
+ StatusChanged("Ready", new EventArgs());
UI(true);
LittleHelp.CompleteTask(taskID);
return s;
@@ -107,12 +223,47 @@ private void UI(bool UI)
public class LabrinthResults
{
+ public class DownloadManager
+ {
+ public class File
+ {
+ public Hashes hashes { get; set; }
+ public string url { get; set; }
+ public string filename { get; set; }
+ public bool primary { get; set; }
+ public int size { get; set; }
+ }
+ public class DownloadLink
+ {
+ public string id { get; set; }
+ public string project_id { get; set; }
+ public string author_id { get; set; }
+ public bool featured { get; set; }
+ public string name { get; set; }
+ public string version_number { get; set; }
+ public string changelog { get; set; }
+ public object changelog_url { get; set; }
+ public DateTime date_published { get; set; }
+ public int downloads { get; set; }
+ public string version_type { get; set; }
+ public List files { get; set; }
+ public List