Skip to content

Commit

Permalink
Merge pull request #7 from SeaDevTeam/bugFix2
Browse files Browse the repository at this point in the history
A little Big Update
  • Loading branch information
NoobNotFound authored Jun 28, 2022
2 parents cc7a33e + 9383ed1 commit 622aae7
Show file tree
Hide file tree
Showing 17 changed files with 537 additions and 186 deletions.
1 change: 1 addition & 0 deletions SDLauncher UWP/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</Style>
</ResourceDictionary>
<ResourceDictionary Source="/Resources/ExpanderStyle.xaml"/>
<ResourceDictionary Source="/Resources/AcrylicButton.xaml"/>
</winui:XamlControlsResources.MergedDictionaries>
</winui:XamlControlsResources>
</Application.Resources>
Expand Down
13 changes: 6 additions & 7 deletions SDLauncher UWP/Dialogs/Login.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<Button Style="{ThemeResource AccentButtonStyle}" x:Name="btnChooseAcc" Click="btnChooseAcc_Click" HorizontalAlignment="Center" Margin="0,5,0,0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Choose an account" VerticalAlignment="Center"/>
<FontIcon Glyph="&#xEBE7;" Margin="2,3,0,0" FontWeight="SemiBold" VerticalAlignment="Bottom"/>
<FontIcon Glyph="&#xE748;" />
</StackPanel>
</Button>
</StackPanel>
Expand Down Expand Up @@ -83,7 +83,6 @@
<TextBlock VerticalAlignment="Center" FontSize="15" FontWeight="SemiBold" Text="Choose an account"/>
</StackPanel>
<StackPanel VerticalAlignment="Center" Margin="0,0,0,4" Orientation="Horizontal" Grid.Column="1">

<Button VerticalAlignment="Center" Width="30" Margin="0,0,5,0" Click="btnDel_Click" x:Name="btnDel" Background="Transparent" BorderThickness="0" Padding="5,7">
<FontIcon Glyph="&#xe74d;" FontSize="17"/>
</Button>
Expand Down Expand Up @@ -243,16 +242,16 @@
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" x:Name="imgBody"/>
<winui:DropDownButton Margin="0,5,0,0" Grid.Row="1" HorizontalAlignment="Right">
<winui:DropDownButton Margin="0,5,0,0" Grid.Row="1" x:Name="btnDownloadSkin" HorizontalAlignment="Right">
<winui:DropDownButton.Content>
<SymbolIcon Symbol="Download"/>
</winui:DropDownButton.Content>
<winui:DropDownButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Download body"/>
<MenuFlyoutItem Text="Download head"/>
<MenuFlyoutItem Text="Download head 3D"/>
<MenuFlyoutItem Text="Download skin"/>
<MenuFlyoutItem Tag="Body" Click="mitDownloadSkin_Click" Text="Download body"/>
<MenuFlyoutItem Tag="Head" Click="mitDownloadSkin_Click" Text="Download head"/>
<MenuFlyoutItem Tag="Head3D" Click="mitDownloadSkin_Click" Text="Download head 3D"/>
<MenuFlyoutItem Tag="Skin" Click="mitDownloadSkin_Click" Text="Download skin"/>
</MenuFlyout>
</winui:DropDownButton.Flyout>
</winui:DropDownButton>
Expand Down
71 changes: 55 additions & 16 deletions SDLauncher UWP/Dialogs/Login.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ private async void btnMSLogin_Click(object sender, RoutedEventArgs e)
this.Hide();
_ = await MessageBox.Show("Error", "User canceld the login!", MessageBoxButtons.Ok);
vars.session = tempsession;
vars.UserName = tempsession.Username;
_ = this.ShowAsync();
}
else if (result == MSLogin.Exceptions.NoAccount)
{
this.Hide();
_ = await MessageBox.Show("Error", "You don't have an Minecraft profile on that Microsoft account!", MessageBoxButtons.Ok);
vars.session = tempsession;
vars.UserName = tempsession.Username;
_ = this.ShowAsync();
}
else if (result == MSLogin.Exceptions.ConnectFailed)
Expand All @@ -79,14 +77,12 @@ private async void btnMSLogin_Click(object sender, RoutedEventArgs e)
if (tempsession != null)
{
vars.session = tempsession;
vars.UserName = tempsession.Username;
}
_ = this.ShowAsync();
UpdateAccounts();
}
else if (result == MSLogin.Exceptions.Success)
{
vars.UserName = vars.session.Username;
this.Hide();
}
UI(true);
Expand All @@ -100,7 +96,6 @@ private void btnMSLogout_Click(object sender, RoutedEventArgs e)
private void UpdateSession(MSession session)
{
vars.session = session;
vars.UserName = session.Username.ToString();
this.Hide();
}

Expand Down Expand Up @@ -193,7 +188,7 @@ private void LoginFromCache(object sender, RoutedEventArgs e)
isSelectionMode = false;
}
}
if(vars.Accounts.Count == 1)
if (vars.Accounts.Count == 1)
{
isSelectionMode = false;
}
Expand Down Expand Up @@ -254,7 +249,6 @@ private void LogOutFromCache(object sender, RoutedEventArgs e)
if (item.Count == vars.CurrentAccountCount)
{
vars.session = null;
vars.UserName = "";
vars.CurrentAccountCount = null;
}

Expand All @@ -275,7 +269,6 @@ private void LogOutFromCache(object sender, RoutedEventArgs e)
if (item.Count == vars.CurrentAccountCount)
{
vars.session = null;
vars.UserName = "";
vars.CurrentAccountCount = null;
}
}
Expand All @@ -284,7 +277,6 @@ private void LogOutFromCache(object sender, RoutedEventArgs e)
if (item.Count == vars.CurrentAccountCount)
{
vars.session = null;
vars.UserName = "";
vars.CurrentAccountCount = null;
}
}
Expand Down Expand Up @@ -318,7 +310,6 @@ void AddAccount(MSession session)
vars.AccountsCount++;
}
vars.session = session;
vars.UserName = session.Username;
vars.CurrentAccountCount = vars.AccountsCount;
this.Hide();
}
Expand Down Expand Up @@ -356,7 +347,7 @@ private void btnBack_Click(object sender, RoutedEventArgs e)
gridChoose.Visibility = Visibility.Collapsed;
gridSettingsOnline.Visibility = Visibility.Collapsed;
}

public string selectedSkinUUID;
private void btnSettings_Click(object sender, RoutedEventArgs e)
{
if (sender is MenuFlyoutItem itm)
Expand All @@ -368,8 +359,9 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
if (item.Type == "Offline")
{
itmRename.IsEnabled = true;
imgBody.Source = new BitmapImage(new Uri("https://minotar.net/body/noob"));
prpSettings.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/avatar/noob"));
imgBody.Source = new BitmapImage(new Uri("https://minotar.net/body/MHF_Steve"));
prpSettings.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/helm/MHF_Steve"));
selectedSkinUUID = "MHF_Steve";
txtTypeSettings.Text = "Offline Account";
fnticoAcTypeSettings.Glyph = item.TypeIconGlyph;
prpSettings.DisplayName = item.UserName;
Expand All @@ -384,8 +376,10 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
}
else
{
bodyImagesorce = "https://minotar.net/" + item.UUID;
imgBody.Source = new BitmapImage(new Uri("https://minotar.net/body/" + item.UUID));
prpSettings.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/helm/" + item.UUID));
itmRename.IsEnabled = false;
selectedSkinUUID = item.UUID;
txtTypeSettings.Text = "Microsoft Account";
fnticoAcTypeSettings.Glyph = item.TypeIconGlyph;
prpSettings.DisplayName = item.UserName;
Expand Down Expand Up @@ -513,7 +507,6 @@ private void Rename(TextBox txtbx)
if (vars.CurrentAccountCount == item.Count)
{
vars.session = MSession.GetOfflineSession(txtbxRename.Text);
vars.UserName = txtbxRename.Text;
}
item.UserName = txtbxRename.Text;
txtSettingsPrpName.Text = txtbxRename.Text;
Expand Down Expand Up @@ -747,7 +740,53 @@ private void btnDel_Click(object sender, RoutedEventArgs e)
}
}
}
private async void mitDownloadSkin_Click(object sender, RoutedEventArgs e)
{
btnDownloadSkin.IsEnabled = false;
int taskID = LittleHelp.AddTask("Download image");
try
{
string link = "https://minotar.net/";
if (sender is MenuFlyoutItem mit)
{
switch (mit.Tag.ToString())
{
case "Head":
link += "helm/" + selectedSkinUUID + "/1000";
break;
case "Head3D":
link += "cube/" + selectedSkinUUID + "/1000";
break;
case "Body":
link += "body/" + selectedSkinUUID + "/1000";
break;
case "Skin":
link += "skin/" + selectedSkinUUID;
break;
}
var f = await Windows.Storage.DownloadsFolder.CreateFileAsync(mit.Tag.ToString() + selectedSkinUUID);
var path = f.Path;
f = null;
using (var client = new HttpClientDownloadWithProgress(link, path))
{
client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) =>
{
if (progressPercentage == 100)
{
LittleHelp.CompleteTask(taskID,true);
client.Dispose();
}
};


await client.StartDownload();
}
}
}
catch
{
LittleHelp.CompleteTask(taskID, false);
}
btnDownloadSkin.IsEnabled = true;
}
}
}
43 changes: 26 additions & 17 deletions SDLauncher UWP/Helpers/Labrinth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static int AddTask(string name)
{
return vars.Launcher.TasksHelper.AddTask(name);
}
public static void CompleteTask(int ID,bool? IsSuccess = null)
public static void CompleteTask(int ID,bool IsSuccess = true)
{
vars.Launcher.TasksHelper.CompleteTask(ID);
vars.Launcher.TasksHelper.CompleteTask(ID,IsSuccess);
}
}
public class Labrinth
Expand Down Expand Up @@ -67,7 +67,7 @@ public async void DownloadMod(LabrinthResults.DownloadManager.File file,CmlLib.C
else
{
this.MainUIChangeRequested(this, new SDLauncher.UIChangeRequestedEventArgs(true));
LittleHelp.CompleteTask(DownloadTaskID);
LittleHelp.CompleteTask(DownloadTaskID,true);
}
}
}
Expand All @@ -83,19 +83,29 @@ private async void ModrinthDownload(string link,string folderdir, string fileNam
CreationCollisionOption.ReplaceExisting);
string path = file.Path;
file = null;
using (var client = new HttpClientDownloadWithProgress(link, path))
try
{
client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => {
StatusChanged("Download " + fileName, new EventArgs());
this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: Convert.ToInt32(progressPercentage)));
if(progressPercentage == 100)
using (var client = new HttpClientDownloadWithProgress(link, path))
{
client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) =>
{
this.DownloadFileCompleted();
client.Dispose();
}
};
StatusChanged("Download " + fileName, new EventArgs());
this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: Convert.ToInt32(progressPercentage)));
if (progressPercentage == 100)
{
this.DownloadFileCompleted();
client.Dispose();
LittleHelp.CompleteTask(DownloadTaskID);
}
};

await client.StartDownload();
await client.StartDownload();
}
}
catch
{
DownloadFileCompleted();
LittleHelp.CompleteTask(DownloadTaskID,false);
}

}
Expand All @@ -108,7 +118,6 @@ 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<LabrinthResults.SearchResult> Search(string name, int? limit = null, LabrinthResults.SearchSortOptions sortOptions = LabrinthResults.SearchSortOptions.Relevance, LabrinthResults.SearchCategories[] categories = null)
Expand Down Expand Up @@ -159,7 +168,7 @@ private void DownloadFileCompleted()
{
StatusChanged("Ready", new EventArgs());
UI(true);
LittleHelp.CompleteTask(taskID);
LittleHelp.CompleteTask(taskID, false);
return null;
}
}
Expand Down Expand Up @@ -191,7 +200,7 @@ private void DownloadFileCompleted()
{
UI(true);
}
LittleHelp.CompleteTask(taskID);
LittleHelp.CompleteTask(taskID,false);
return null;
}
}
Expand All @@ -215,7 +224,7 @@ private void DownloadFileCompleted()
{
StatusChanged("Ready", new EventArgs());
UI(true);
LittleHelp.CompleteTask(taskID);
LittleHelp.CompleteTask(taskID, false);
return null;
}
}
Expand Down
Loading

0 comments on commit 622aae7

Please sign in to comment.