Skip to content

Commit

Permalink
Instances are working now and progressbar finally displays progress
Browse files Browse the repository at this point in the history
  • Loading branch information
deltaDelete committed Jul 2, 2021
1 parent e978b06 commit 31fd5a0
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 18 deletions.
15 changes: 15 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
using System.Windows.Controls;
using Newtonsoft.Json;
using System.IO;
using System.Collections.Generic;
using static Fluetta.Pages.Settings;

namespace Fluetta
{
public partial class MainWindow
{
public static List<string> versionIds = new List<string>();
public static string latestRelease;
public MainWindow()
{
//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
Expand All @@ -29,9 +33,20 @@ public MainWindow()
{
File.WriteAllText(Settings.SettingsData.minecraftPath + "\\launcher_profiles.json", "{\n \"profiles\": {\n\n }\n}");
}
LoadVersions();
Instances.InstanceList = Instances.ListDirs(Settings.SettingsData.minecraftPath);
InitializeComponent();
}
public async static void LoadVersions()
{
CmlLib.Core.Version.MVersionCollection versions = await new CmlLib.Core.CMLauncher(new CmlLib.Core.MinecraftPath(SettingsData.minecraftPath)).GetAllVersionsAsync();
foreach (CmlLib.Core.Version.MVersionMetadata versionMetadata in versions)
{
versionIds.Add(versionMetadata.Name);
}
latestRelease = versions.LatestReleaseVersion.Name;
}


private void NavigationView_Loaded(object sender, RoutedEventArgs e)
{
Expand Down
35 changes: 35 additions & 0 deletions Pages/EditDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<ui:ContentDialog x:Class="Fluetta.Pages.EditDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Fluetta.Pages"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:res="clr-namespace:Fluetta.Properties"
x:Name="Dialog"
Title="{x:Static res:Resources.Edit}"
PrimaryButtonText="{x:Static res:Resources.Save}"
PrimaryButtonStyle="{DynamicResource AccentButtonStyle}"
SecondaryButtonText="{x:Static res:Resources.Cancel}"
mc:Ignorable="d"
d:DesignHeight="1000" d:DesignWidth="800">
<ScrollViewer>
<ui:SimpleStackPanel Spacing="12" Margin="0 0 21 0">
<TextBox ui:ControlHelper.Header="{x:Static res:Resources.Name}" x:Name="Name"/>
<ComboBox ui:ControlHelper.Header="{x:Static res:Resources.Version}" x:Name="Version" HorizontalAlignment="Stretch"/>
<TextBox ui:ControlHelper.Header="{x:Static res:Resources.FolderName}" x:Name="FolderName"/>
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="5">
<TextBox ui:ControlHelper.Header="{x:Static res:Resources.JavaPath}" MinWidth="300" MaxWidth="312" x:Name="JavaDir" Width="291"/>
<Button Content="{x:Static res:Resources.Browse}" VerticalAlignment="Bottom" Click="BrowseJavaClick" Height="32"/>
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="5">
<TextBox ui:ControlHelper.Header="{x:Static res:Resources.Resolution}" x:Name="ResX" Width="128"/>
<TextBlock Text="x" VerticalAlignment="Bottom" Margin="0 10" Foreground="Gray"/>
<TextBox ui:ControlHelper.Header=" " x:Name="ResY" Width="128"/>
<Button Content="{x:Static res:Resources.Reset}" VerticalAlignment="Bottom" Height="32" Click="ResResetClick" MinWidth="89"/>
</ui:SimpleStackPanel>
<TextBox ui:ControlHelper.Header="{x:Static res:Resources.JVMArgs}" x:Name="JVMArgs"/>
<TextBox ui:ControlHelper.Header="{x:Static res:Resources.MaxRAM}" x:Name="MaxRAM"/>
</ui:SimpleStackPanel>
</ScrollViewer>
</ui:ContentDialog>
44 changes: 44 additions & 0 deletions Pages/EditDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ModernWpf.Controls;
using static Fluetta.Pages.Settings;

namespace Fluetta.Pages
{
/// <summary>
/// Логика взаимодействия для EditDialog.xaml
/// </summary>
public partial class EditDialog : ContentDialog
{
public EditDialog()
{
InitializeComponent();
}

private void BrowseJavaClick(object sender, RoutedEventArgs e)
{
Ookii.Dialogs.Wpf.VistaOpenFileDialog fileDialog = new Ookii.Dialogs.Wpf.VistaOpenFileDialog
{
DefaultExt = "exe"
};
fileDialog.ShowDialog();
JavaDir.Text = fileDialog.FileName;
}

private void ResResetClick(object sender, RoutedEventArgs e)
{
ResX.Text = SettingsData.resX;
ResY.Text = SettingsData.resY;
}
}
}
21 changes: 21 additions & 0 deletions Pages/Home.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -43,6 +45,8 @@ private async void PlayClick(object sender, RoutedEventArgs e)
selectedProfile.LastUsed = DateTime.Now;
File.WriteAllText($"{instance_path}\\instance_settings.json", JsonConvert.SerializeObject(selectedProfile));
var launcher = new CMLauncher(FMinecraftPath.GetPath(SettingsData.minecraftPath, $"{SettingsData.minecraftPath}\\instances\\{selectedProfile.InstanceDir}"));
launcher.FileChanged += Launcher_FileChanged;
launcher.ProgressChanged += Launcher_ProgressChanged;
var launchOption = new MLaunchOption
{
MaximumRamMb = (!string.IsNullOrEmpty(selectedProfile.MaxRAM)) ? int.Parse(selectedProfile.MaxRAM) : int.Parse(SettingsData.maxRAM),
Expand All @@ -56,6 +60,7 @@ private async void PlayClick(object sender, RoutedEventArgs e)

process.Start();
ProgressBar.Visibility = Visibility.Hidden;
ProgressBar.IsIndeterminate = true;
PlayBtn.IsEnabled = true;
PlayBtn.Content = Properties.Resources.PlayBtn;
}
Expand Down Expand Up @@ -99,5 +104,21 @@ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs
File.WriteAllText(@"selected_profile.txt", ComboBox.SelectedItem.ToString());
System.Diagnostics.Debug.WriteLine("[!] Profile selected");
}
// Event Handler. Show download progress
private void Launcher_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
System.Diagnostics.Debug.WriteLine($"[!] Download progress - {e}");
ProgressBar.IsIndeterminate = false;
ProgressBar.Maximum = 100;
ProgressBar.Value = e.ProgressPercentage;
}

private void Launcher_FileChanged(CmlLib.Core.Downloader.DownloadFileChangedEventArgs e)
{
System.Diagnostics.Debug.WriteLine($"[!] File changed progress - {e}");
ProgressBar.IsIndeterminate = false;
ProgressBar.Maximum = e.TotalFileCount;
ProgressBar.Value = e.ProgressedFileCount;
}
}
}
49 changes: 43 additions & 6 deletions Pages/Instances.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,47 @@
d:DesignHeight="450" d:DesignWidth="760" d:Background="White"
Loaded="Page_Loaded"
Title="Instances">

<ScrollViewer>
<ui:SimpleStackPanel Spacing="24" Margin="{StaticResource ControlPageContentMargin}">
<ui:ListView x:Name="ListView"/>
</ui:SimpleStackPanel>
</ScrollViewer>
<Grid>
<ScrollViewer>
<!--<ui:SimpleStackPanel Spacing="24" Margin="{StaticResource ControlPageContentMargin}">
<ui:ListView x:Name="ListView"/>
</ui:SimpleStackPanel>-->
<ui:SimpleStackPanel>
<ui:GridView x:Name="InstanceGrid" SelectionMode="Single">
<ui:GridView.ItemContainerStyle>
<Style TargetType="ui:GridViewItem">
<Setter Property="Margin" Value="10" />
</Style>
</ui:GridView.ItemContainerStyle>
<ui:GridView.ItemTemplate>
<DataTemplate>
<Grid>
<ui:ThemeShadowChrome Depth="30">
<Grid Width="216" Height="128">
<Rectangle RadiusX="4" RadiusY="4" Fill="{DynamicResource SystemControlBackgroundChromeMediumBrush}"/>
<ui:SimpleStackPanel Spacing="10">
<TextBlock Text="{Binding Name}" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="5 10"/>
<TextBlock Text="{Binding VersionId}" FontSize="16" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Spacing="5">
<Button Content="{x:Static res:Resources.Edit}" Click="EditClick"/>
<Button Content="{x:Static res:Resources.Delete}" Click="DeleteClick"/>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</Grid>
</ui:ThemeShadowChrome>
</Grid>
</DataTemplate>
</ui:GridView.ItemTemplate>
<ui:GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Margin="25" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ui:GridView.ItemsPanel>
</ui:GridView>
</ui:SimpleStackPanel>
</ScrollViewer>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10" Click="NewInstanceClick" Style="{DynamicResource AccentButtonStyle}">
<ui:FontIcon FontFamily="{StaticResource SegoeMDL2}" Glyph="&#xE710;"/>
</Button>
</Grid>
</Page>
124 changes: 113 additions & 11 deletions Pages/Instances.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static Fluetta.Pages.Settings;
using static Fluetta.Instances;
using System.Collections.ObjectModel;
using System.IO;
using Newtonsoft.Json;

namespace Fluetta.Pages
{
Expand All @@ -29,7 +22,116 @@ public Instances()

private void Page_Loaded(object sender, RoutedEventArgs e)
{
ListView.ItemsSource = GetInstanceNames(ListDirs(SettingsData.minecraftPath));
//ListView.ItemsSource = GetInstanceNames(ListDirs(SettingsData.minecraftPath));
SetItemsSource(InstanceGrid);
}

private async void DeleteClick(object sender, RoutedEventArgs e)
{
Instance sndr = (Instance)((Button)sender).DataContext;
ModernWpf.Controls.ContentDialog contentDialog = new ModernWpf.Controls.ContentDialog()
{
PrimaryButtonText = Properties.Resources.Yes,
SecondaryButtonText = Properties.Resources.No,
Title = Properties.Resources.Delete,
Content = Properties.Resources.DeletionDialog
};
ModernWpf.Controls.ContentDialogResult result = await contentDialog.ShowAsync();
if (result == ModernWpf.Controls.ContentDialogResult.Primary)
{
Directory.Delete($"{SettingsData.minecraftPath}\\instances\\{sndr.InstanceDir}", true);
SetItemsSource(InstanceGrid);
System.Diagnostics.Debug.WriteLine($"[!] {sndr.Name} is successfully deleted");
}
}
public static void SetItemsSource(ModernWpf.Controls.GridView gridView)
{
List<Instance> tempList = GetInstanceObjects(SettingsData.minecraftPath);
ObservableCollection<Instance> Items = new ObservableCollection<Instance>(tempList);
gridView.ItemsSource = Items;
}
private async void EditClick(object sender, RoutedEventArgs e)
{
Instance sndr = (Instance)((Button)sender).DataContext;
EditDialog editDialog = new EditDialog();
editDialog.Name.Text = sndr.Name;
editDialog.Version.ItemsSource = MainWindow.versionIds; //new CmlLib.Core.CMLauncher(new CmlLib.Core.MinecraftPath(SettingsData.minecraftPath)).GetAllVersions();
editDialog.Version.SelectedItem = sndr.VersionId;
editDialog.FolderName.Text = sndr.InstanceDir;
editDialog.JavaDir.Text = sndr.JavaDir;
editDialog.ResX.Text = sndr.ResX;
editDialog.ResY.Text = sndr.ResY;
editDialog.JVMArgs.Text = sndr.JVMArgs;
editDialog.MaxRAM.Text = sndr.MaxRAM;
ModernWpf.Controls.ContentDialogResult result = await editDialog.ShowAsync();
if (result == ModernWpf.Controls.ContentDialogResult.Primary)
{
System.Diagnostics.Debug.WriteLine("[!] Primary button pressed");
File.WriteAllText($"{SettingsData.minecraftPath}\\instances\\{sndr.InstanceDir}\\instance_settings.json", JsonConvert.SerializeObject(new Instance()
{
Name = editDialog.Name.Text,
VersionId = editDialog.Version.Text,
Created = sndr.Created,
LastUsed = sndr.LastUsed,
InstanceDir = editDialog.FolderName.Text,
JavaDir = editDialog.JavaDir.Text,
ResX = editDialog.ResX.Text,
ResY = editDialog.ResY.Text,
JVMArgs = editDialog.JVMArgs.Text,
MaxRAM = editDialog.MaxRAM.Text
}
));
if (editDialog.FolderName.Text != sndr.InstanceDir)
{
Directory.Move($"{SettingsData.minecraftPath}\\instances\\{sndr.InstanceDir}", $"{SettingsData.minecraftPath}\\instances\\{editDialog.FolderName.Text}");
}
SetItemsSource(InstanceGrid);
}
}
private async void NewInstanceClick(object sender, RoutedEventArgs e)
{
EditDialog createDialog = new EditDialog();
createDialog.Title = Properties.Resources.CreateInstance;
createDialog.PrimaryButtonText = Properties.Resources.Create;
createDialog.Version.ItemsSource = MainWindow.versionIds;
createDialog.Version.SelectedItem = MainWindow.latestRelease;
ModernWpf.Controls.ContentDialogResult result = await createDialog.ShowAsync();
if (result == ModernWpf.Controls.ContentDialogResult.Primary)
{
if (string.IsNullOrEmpty(createDialog.FolderName.Text))
{
createDialog.FolderName.Text = createDialog.Name.Text;
}
if (string.IsNullOrEmpty(createDialog.Name.Text))
{
ModernWpf.Controls.ContentDialog warningDialog = new ModernWpf.Controls.ContentDialog();
warningDialog.Title = Properties.Resources.Attention;
warningDialog.Content = Properties.Resources.NameIsEmpty;
warningDialog.PrimaryButtonText = Properties.Resources.Ok;
await warningDialog.ShowAsync();
createDialog.Closing -= null;
}
else
{
Instance instance = new Instance
{
Name = createDialog.Name.Text,
VersionId = createDialog.Version.Text,
Created = DateTime.Now,
LastUsed = DateTime.Now,
InstanceDir = createDialog.FolderName.Text,
JavaDir = createDialog.JavaDir.Text,
ResX = createDialog.ResX.Text,
ResY = createDialog.ResY.Text,
JVMArgs = createDialog.JVMArgs.Text,
MaxRAM = createDialog.MaxRAM.Text
};
Directory.CreateDirectory($"{SettingsData.minecraftPath}\\instances\\{instance.InstanceDir}");
File.WriteAllText($"{SettingsData.minecraftPath}\\instances\\{instance.InstanceDir}\\instance_settings.json", JsonConvert.SerializeObject(instance));
SetItemsSource(InstanceGrid);
}
}
}

}
}
3 changes: 2 additions & 1 deletion Pages/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ private async void ApplyClick(object sender, RoutedEventArgs e)
ModernWpf.Controls.ContentDialog contentDialog = new ModernWpf.Controls.ContentDialog()
{
PrimaryButtonText = Properties.Resources.Ok,
Title = Properties.Resources.ContextDialogApplied,
Title = Properties.Resources.Attention,
Content = Properties.Resources.ContextDialogApplied
};
await contentDialog.ShowAsync();
}
Expand Down
Loading

0 comments on commit 31fd5a0

Please sign in to comment.