Skip to content

Commit

Permalink
Refactoring and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
TrinityDevelopers committed Apr 8, 2020
1 parent 9853589 commit b896625
Show file tree
Hide file tree
Showing 24 changed files with 120 additions and 55 deletions.
3 changes: 2 additions & 1 deletion ZenovaLauncher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:local="clr-namespace:ZenovaLauncher"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml"
Startup="AppStart">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
4 changes: 4 additions & 0 deletions ZenovaLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ namespace ZenovaLauncher
/// </summary>
public partial class App : Application
{
public void AppStart(object sender, StartupEventArgs e)
{
ProfileManager.instance = new ProfileManager();
}
}
}
File renamed without changes
File renamed without changes
File renamed without changes.
9 changes: 4 additions & 5 deletions ZenovaLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
Icon="zenova_icon.ico"
Title="Zenova Launcher"
Height="600" Width="1000"
MinHeight="600" MinWidth="1000"
Expand Down Expand Up @@ -74,23 +73,23 @@

<mah:HamburgerMenuIconItem
Label="Minecraft: Bedrock"
Tag="MainPage.xaml">
Tag="/Pages/MainPage.xaml">
<mah:HamburgerMenuIconItem.Icon>
<ui:SymbolIcon Symbol="Home" />
</mah:HamburgerMenuIconItem.Icon>
</mah:HamburgerMenuIconItem>

<mah:HamburgerMenuIconItem
Label="News"
Tag="NewsPage.xaml">
Tag="/Pages/NewsPage.xaml">
<mah:HamburgerMenuIconItem.Icon>
<ui:SymbolIcon Symbol="PreviewLink" />
</mah:HamburgerMenuIconItem.Icon>
</mah:HamburgerMenuIconItem>

<mah:HamburgerMenuIconItem
Label="Help"
Tag="HelpPage.xaml">
Tag="/Pages/HelpPage.xaml">
<mah:HamburgerMenuIconItem.Icon>
<ui:SymbolIcon Symbol="Help" />
</mah:HamburgerMenuIconItem.Icon>
Expand All @@ -102,7 +101,7 @@
<mah:HamburgerMenuItemCollection x:Name="NavViewOptions">
<mah:HamburgerMenuIconItem
Label="Settings"
Tag="SettingsPage.xaml">
Tag="/Pages/SettingsPage.xaml">
<mah:HamburgerMenuIconItem.Icon>
<ui:SymbolIcon Symbol="Setting" />
</mah:HamburgerMenuIconItem.Icon>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
xmlns:ui="http://schemas.modernwpf.com/2019"
mc:Ignorable="d">
<Page.Resources>
<ImageBrush x:Key="ImageBackground" ImageSource="zenova_background.png" Stretch="UniformToFill" />
<local:Profiles x:Key="CurrentProfiles" />
<ImageBrush x:Key="ImageBackground" ImageSource="/Assets/zenova_background.png" Stretch="UniformToFill" />
</Page.Resources>

<Grid>
Expand All @@ -25,7 +24,7 @@
<Image
Grid.ColumnSpan="3"
Grid.RowSpan="2"
Source="zenova_banner.png"
Source="/Assets/zenova_banner.png"
Width="250"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Expand Down Expand Up @@ -60,8 +59,7 @@
<Grid Grid.Row="1" Grid.Column="0">
<ComboBox
Style="{StaticResource ProfileBoxStyle}"
ItemsSource="{Binding Source={StaticResource CurrentProfiles}}"
x:Name="ProfileCombo"
x:Name="ProfileBox"
Margin="10,4,10,4"
MinWidth="200"
HorizontalContentAlignment="Left"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class PlayPage : Page
{
public PlayPage() {
InitializeComponent();
ProfileBox.ItemsSource = ProfileManager.instance;
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace ZenovaLauncher
/// </summary>
public partial class ProfilesPage : Page
{
public Profiles ProfilesList;

Predicate<object> releaseFilter = (object item) =>
{
return (item as Profile).Release == true;
Expand All @@ -38,8 +36,7 @@ public partial class ProfilesPage : Page

public ProfilesPage() {
InitializeComponent();
ProfilesList = new Profiles();
ProfileListBox.ItemsSource = ProfilesList;
ProfileListBox.ItemsSource = ProfileManager.instance;

SortProfileList(true);
FilterProfileList();
Expand All @@ -66,16 +63,16 @@ private void DuplicateProfileClick(object sender, RoutedEventArgs e)
{
Profile newProfile = new Profile((sender as FrameworkElement).DataContext as Profile);
int index = 2;
while (ProfilesList.SingleOrDefault(p => p.ProfileName == (newProfile.ProfileName + " (" + index + ")")) != null)
while (ProfileManager.instance.SingleOrDefault(p => p.ProfileName == (newProfile.ProfileName + " (" + index + ")")) != null)
index++;
newProfile.ProfileName += " (" + index + ")";
ProfilesList.Add(newProfile);
ProfileManager.instance.Add(newProfile);
SortProfileList(SortProfileBox.SelectedIndex == 0);
}

private void DeleteProfileClick(object sender, RoutedEventArgs e)
{
ProfilesList.Remove((sender as FrameworkElement).DataContext as Profile);
ProfileManager.instance.Remove((sender as FrameworkElement).DataContext as Profile);
ProfileListBox.Items.Refresh();
}

Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 0 additions & 19 deletions ZenovaLauncher/Profiles/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,4 @@ public Profile(Profile profile) : this(profile.ProfileName, profile._version, pr
public bool Historical { get { return _version.Historical; } }
public bool Release { get { return _version.Release; } }
}

public class Profiles : ObservableCollection<Profile>
{
public Profiles()
{
Add(new Profile("Latest release", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 10, 2)));
Add(new Profile("Latest beta", new MinecraftVersion("1.16.0.55", "uuid", true, false), new DateTime(2020, 1, 20)));
Add(new Profile("This is a very long profile name that could potentially cause problems", new MinecraftVersion("1.14.30.2", "uuid", false, false)));
Add(new Profile("Profile1", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 11, 2)));
Add(new Profile("Profile2", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 1, 2)));
Add(new Profile("Profile3", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 3, 2)));
Add(new Profile("Profile4", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 10, 5)));
Add(new Profile("Profile5", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 11, 12)));
Add(new Profile("Profile6", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 10, 12)));
Add(new Profile("Profile7", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 1, 21)));
Add(new Profile("Profile8", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 10, 21)));
Add(new Profile("Profile9", new MinecraftVersion("1.14.30.2", "uuid", false, false), new DateTime(2019, 1, 23)));
}
}
}
20 changes: 20 additions & 0 deletions ZenovaLauncher/Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZenovaLauncher
{
public class ProfileManager : ObservableCollection<Profile>
{
public static ProfileManager instance;

public ProfileManager()
{
Add(new Profile("Latest release", new MinecraftVersion("1.14.30.2", "uuid")));
Add(new Profile("Latest beta", new MinecraftVersion("1.16.0.55", "uuid", isBeta: true)));
}
}
}
59 changes: 59 additions & 0 deletions ZenovaLauncher/Profiles/VersionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace ZenovaLauncher
{
class VersionManager : ObservableCollection<MinecraftVersion>
{
public static VersionManager instance;

private readonly string _cacheFile = "versions.json";
private readonly HttpClient _client = new HttpClient();

public VersionManager()
{

}

private void ParseList(JArray data)
{
Clear();
// ([name, uuid, isBeta])[]
foreach (JArray o in data.AsEnumerable().Reverse())
{
Add(new MinecraftVersion(o[0].Value<string>(), o[1].Value<string>(), o[2].Value<int>() == 1));
}
}

public async Task LoadFromCache()
{
try
{
using (var reader = File.OpenText(_cacheFile))
{
var data = await reader.ReadToEndAsync();
ParseList(JArray.Parse(data));
}
}
catch (FileNotFoundException)
{ // ignore
}
}

public async Task DownloadList()
{
var resp = await _client.GetAsync("https://mrarm.io/r/w10-vdb");
resp.EnsureSuccessStatusCode();
var data = await resp.Content.ReadAsStringAsync();
File.WriteAllText(_cacheFile, data);
ParseList(JArray.Parse(data));
}
}
}
41 changes: 23 additions & 18 deletions ZenovaLauncher/ZenovaLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>zenova_icon.ico</ApplicationIcon>
<ApplicationIcon>Assets\zenova_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down Expand Up @@ -72,20 +72,21 @@
<Compile Include="Dialogs\AddProfileDialog.xaml.cs">
<DependentUpon>AddProfileDialog.xaml</DependentUpon>
</Compile>
<Compile Include="ModsPage.xaml.cs">
<Compile Include="Pages\ModsPage.xaml.cs">
<DependentUpon>ModsPage.xaml</DependentUpon>
</Compile>
<Compile Include="PlayPage.xaml.cs">
<Compile Include="Pages\PlayPage.xaml.cs">
<DependentUpon>PlayPage.xaml</DependentUpon>
</Compile>
<Compile Include="ProfilesPage.xaml.cs">
<Compile Include="Pages\ProfilesPage.xaml.cs">
<DependentUpon>ProfilesPage.xaml</DependentUpon>
</Compile>
<Compile Include="Profiles\MinecraftVersion.cs" />
<Compile Include="Profiles\Profile.cs" />
<Compile Include="SettingsPage.xaml.cs">
<Compile Include="Pages\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="Profiles\ProfileManager.cs" />
<Page Include="Dialogs\EditProfileDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -94,11 +95,11 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="HelpPage.xaml">
<Page Include="Pages\HelpPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainPage.xaml">
<Page Include="Pages\MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -110,33 +111,33 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="HelpPage.xaml.cs">
<Compile Include="Pages\HelpPage.xaml.cs">
<DependentUpon>HelpPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<Compile Include="Pages\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="ModsPage.xaml">
<Page Include="Pages\ModsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="NewsPage.xaml">
<Page Include="Pages\NewsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PlayPage.xaml">
<Page Include="Pages\PlayPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProfilesPage.xaml">
<Page Include="Pages\ProfilesPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SettingsPage.xaml">
<Page Include="Pages\SettingsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down Expand Up @@ -174,9 +175,10 @@
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="NewsPage.xaml.cs">
<Compile Include="Pages\NewsPage.xaml.cs">
<DependentUpon>NewsPage.xaml</DependentUpon>
</Compile>
<Compile Include="Profiles\VersionManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand All @@ -203,7 +205,7 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="zenova_icon.ico" />
<Resource Include="Assets\zenova_icon.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
Expand All @@ -215,12 +217,15 @@
<PackageReference Include="ModernWpfUI.MahApps">
<Version>0.8.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Resource Include="zenova_background.png" />
<Resource Include="Assets\zenova_background.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="zenova_banner.png" />
<Resource Include="Assets\zenova_banner.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit b896625

Please sign in to comment.