Skip to content

Commit

Permalink
Beautify code, Display Version number in Settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGenaue committed Oct 28, 2016
1 parent e669c71 commit d9c8f2b
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 123 deletions.
169 changes: 88 additions & 81 deletions WarframeMarketClient/GUI/Tabs/Tab_Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,97 +7,96 @@
xmlns:converter="clr-namespace:WarframeMarketClient.GUI.Converter"
mc:Ignorable="d"
x:Name="self"
d:DesignHeight="300" d:DesignWidth="300">
d:DesignHeight="600" d:DesignWidth="400">
<UserControl.Resources>
<converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<converter:BoolToNegatedBoolConverter x:Key="BoolToNegatedBoolConverter"/>
</UserControl.Resources>

<ScrollViewer HorizontalScrollBarVisibility="Disabled">

<StackPanel>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="10,0" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="General settings:" Grid.Column="0"/>
<Button x:Name="updateButton" Content="Update available" Grid.Column="1" Visibility="{Binding UpdateAvailable,Converter={StaticResource BoolToVisibilityConverter}}" Click="updateButton_Click" />
</Grid>

<Grid Margin="25,5,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel >
<CheckBox x:Name="defaultOnline" Content="Online on Site when game not running" IsChecked="{Binding DefaultOnline}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
<CheckBox x:Name="limitAutocomplete" Margin="0,5,0,0" Content="Limit Autocomplete to 7 elements" IsChecked="{Binding LimitAutoComplete}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
<CheckBox x:Name="perserveBox" Margin="0,5" Content="Perserve chats closed by other party" IsChecked="{Binding PerserveChats}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
</StackPanel>
<StackPanel Margin="25,0,0,0" Grid.Column="2">
<CheckBox x:Name="autostartBox" Content="Autostart" IsChecked="{Binding Autostart}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}" />
<CheckBox x:Name="minimizeBox" Margin="0,5" Content="Minimize to Tray" IsChecked="{Binding ToTray}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
</StackPanel>
</Grid>

<Label Content="Sound when receiving new Message:"/>
<Grid Margin="25,5,25,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="soundBox"
Margin="0,0"
Grid.Column="0"
IsEditable="False"
IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"
ItemsSource="{Binding Path=AvailableSounds}"
SelectedValue="{Binding ChoosenSoundFile}"
/>
<Button x:Name="importSound" Content="Add Own Sound File" Grid.Column="1" Margin="10,0,0,0" Click="importSound_Click" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}" />
</Grid>
<StackPanel Margin="10,0" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="General settings:" Grid.Column="0"/>
<Button x:Name="updateButton"
Content="{Binding Path=ApplicationState.LatestVersion}"
ContentStringFormat="Update available: {0}"
Grid.Column="1"
Visibility="{Binding ApplicationState.UpdateAvailable, Converter={StaticResource BoolToVisibilityConverter}}"
Click="updateButton_Click"/>
</Grid>

<Grid Margin="25,5,25,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Margin="25,5,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel >
<CheckBox x:Name="defaultOnline" Content="Online on Site when game not running" IsChecked="{Binding DefaultOnline}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
<CheckBox x:Name="limitAutocomplete" Margin="0,5,0,0" Content="Limit Autocomplete to 7 elements" IsChecked="{Binding LimitAutoComplete}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
<CheckBox x:Name="perserveBox" Margin="0,5" Content="Perserve chats closed by other party" IsChecked="{Binding PerserveChats}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
</StackPanel>
<StackPanel Margin="25,0,0,0" Grid.Column="2">
<CheckBox x:Name="autostartBox" Content="Autostart" IsChecked="{Binding Autostart}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}" />
<CheckBox x:Name="minimizeBox" Margin="0,5" Content="Minimize to Tray" IsChecked="{Binding ToTray}" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"/>
</StackPanel>
</Grid>

<Label Content="Volume" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,0"></Label>
<Slider Value="{Binding Volume}"
Grid.Column="1"
VerticalAlignment="Center"
Minimum="0" Maximum="1"
IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"
TickFrequency="0.01"
LargeChange="0.1"
SmallChange="0.05"
IsMoveToPointEnabled="True"
AutoToolTipPlacement="TopLeft"
AutoToolTipPrecision="2"
Focusable="True"
IsTabStop="True"
/>
</Grid>
<Label Content="Sound when receiving new Message:"/>
<Grid Margin="25,5,25,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="soundBox"
Margin="0,0"
Grid.Column="0"
IsEditable="False"
IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"
ItemsSource="{Binding Path=AvailableSounds}"
SelectedValue="{Binding ChoosenSoundFile}"
/>
<Button x:Name="importSound" Content="Add Own Sound File" Grid.Column="1" Margin="10,0,0,0" Click="importSound_Click" IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}" />
</Grid>

<Grid Margin="25,5,25,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

</StackPanel>
<Label Content="Volume" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,0"></Label>
<Slider Value="{Binding Volume}"
Grid.Column="1"
VerticalAlignment="Center"
Minimum="0" Maximum="1"
IsEnabled="{Binding ApplicationState.IsValidating,Converter={StaticResource BoolToNegatedBoolConverter}}"
TickFrequency="0.01"
LargeChange="0.1"
SmallChange="0.05"
IsMoveToPointEnabled="True"
AutoToolTipPlacement="TopLeft"
AutoToolTipPrecision="2"
Focusable="True"
IsTabStop="True"
/>
</Grid>

<StackPanel Grid.Row="1" Margin="10,5">
<Label x:Name="label" Content="Session Cookie:"/>
<StackPanel Margin="25,5">

<TextBox x:Name="tokenBox" Margin="0,0,0,10" Text="{Binding SessionTokenInput, ElementName=self, UpdateSourceTrigger=PropertyChanged}" KeyDown="tokenBox_KeyDown" IsEnabled="{Binding ApplicationState.IsValidating, Converter={StaticResource BoolToNegatedBoolConverter}}" />
<Button x:Name="saveButton" Height="22" Content="Save" Click="saveButton_Click" Visibility="{Binding ApplicationState.IsValidating, ConverterParameter=I, Converter={StaticResource BoolToVisibilityConverter}}"/>
<ProgressBar x:Name="progressBar" Height="22" Minimum="0" Maximum="100" Value="{Binding ApplicationState.ValidationProgress}" Visibility="{Binding ApplicationState.IsValidating, Converter={StaticResource BoolToVisibilityConverter}}"/>
</StackPanel>

<StackPanel Margin="10,5">
<Label x:Name="label" Content="Session Cookie:"/>
<StackPanel Margin="25,5">

<TextBox x:Name="tokenBox" Margin="0,0,0,10" Text="{Binding SessionTokenInput, ElementName=self, UpdateSourceTrigger=PropertyChanged}" KeyDown="tokenBox_KeyDown" IsEnabled="{Binding ApplicationState.IsValidating, Converter={StaticResource BoolToNegatedBoolConverter}}" />
<Button x:Name="saveButton" Height="22" Content="Save" Click="saveButton_Click" Visibility="{Binding ApplicationState.IsValidating, ConverterParameter=I, Converter={StaticResource BoolToVisibilityConverter}}"/>
<ProgressBar x:Name="progressBar" Height="22" Minimum="0" Maximum="100" Value="{Binding ApplicationState.ValidationProgress}" Visibility="{Binding ApplicationState.IsValidating, Converter={StaticResource BoolToVisibilityConverter}}"/>

<Grid Margin="0,25,0,0">
<Grid.ColumnDefinitions>
Expand All @@ -109,9 +108,17 @@
</Grid>

</StackPanel>
</StackPanel>

<StackPanel Margin="10,0">
<Label x:Name="version"
Content="{Binding Path=ApplicationState.Version}"
ContentStringFormat="Version {0}"
Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"
FontSize="8"
HorizontalAlignment="Right"/>
</StackPanel>

</StackPanel>

</Grid>

</ScrollViewer>
</UserControl>
19 changes: 6 additions & 13 deletions WarframeMarketClient/Logic/Webhelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,36 +162,29 @@ private static void getCsrfToken()

}

public static bool CheckUpdate()
public static Version CheckUpdate()
{
Version version = Assembly.GetEntryAssembly().GetName().Version;

#if DEBUG // not checking updates when debugging
return true;
return null;
#endif

using (HttpWebResponse response = Webhelper.GetPage("https://api.github.com/repos/Versalkul/WarframeMarketClient/releases/latest"))
{
if (response == null) return false;
if (response == null) return null;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
JObject json = JObject.Parse(reader.ReadToEnd());
JToken vNum = json.GetValue("tag_name");
if (vNum == null) return false;
if (vNum == null) return null;
try // incase the tag name contains bullshit
{
Version newVersion = new Version(vNum.ToString());
return (version.Major<newVersion.Major||version.Minor<newVersion.Minor||version.Build<newVersion.Build);

return newVersion;
}
catch
{
return false;
return null;
}

}


}
}

Expand Down
61 changes: 44 additions & 17 deletions WarframeMarketClient/Model/ApplicationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Data;
using WarframeMarketClient.Logic;
Expand Down Expand Up @@ -60,21 +57,15 @@ private void Initialize() // Initializes that need the ApplicationState
Settings.LoadSettings();
Task.Factory.StartNew(() => { ItemMap.getTypeMap();ItemMap.SaveMap(); }); // inits the webapi and gets an usefull result
Plimper = new SoundViewModel();
Task.Factory.StartNew(() => Settings.UpdateAvailable = Webhelper.CheckUpdate());
Task.Factory.StartNew(() => LatestVersion = Webhelper.CheckUpdate());
}

#endregion


#region Properties


public Logger Logger { get; private set; }

private event EventHandler<List<ChatMessage>> newMessage;

public event EventHandler<List<ChatMessage>> NewMessage { add { newMessage += value; } remove { newMessage -= value; } }

#region SessionToken
private string sessionToken="";

public string SessionToken
Expand Down Expand Up @@ -124,14 +115,12 @@ public string SessionToken

});
}
}


public MarketManager Market { get; private set; }
}
#endregion

public string Username { get; set; } = "";


#region OnlineState
private OnlineState onlineState;
public OnlineState OnlineState { get
{
Expand All @@ -152,7 +141,13 @@ public OnlineState DefaultState
get { return defaultState; }
set { defaultState = value; OnPropertyChanged(nameof(DefaultState)); if (OnlineState == OnlineState.ONLINE || OnlineState == OnlineState.OFFLINE) OnlineState = DefaultState; }
}
#endregion

#region Items n Chats

private event EventHandler<List<ChatMessage>> newMessage;

public event EventHandler<List<ChatMessage>> NewMessage { add { newMessage += value; } remove { newMessage -= value; } }


private ObservableCollection<WarframeItem> sellItems;
Expand Down Expand Up @@ -187,6 +182,8 @@ public ObservableCollection<ChatViewModel> Chats
OnPropertyChanged(nameof(Chats));
}
}
#endregion

#region Validating etc props

public bool HasUsername { get { return !String.IsNullOrWhiteSpace(instance.Username); } }
Expand All @@ -204,11 +201,41 @@ public int ValidationProgress
}

#endregion

#region Version
public Version Version { get { return System.Reflection.Assembly.GetEntryAssembly().GetName().Version; } }

private Version latestVersion;
public Version LatestVersion
{
get { return latestVersion; }
set {
latestVersion = value;
OnPropertyChanged("LatestVersion");
OnPropertyChanged("UpdateAvailable");
}
}

public Boolean UpdateAvailable
{
get
{
return LatestVersion != null &&
(Version.Major < LatestVersion.Major || Version.Minor < LatestVersion.Minor || Version.Build < LatestVersion.Build);
}
}

#endregion

public MarketManager Market { get; private set; }

public RunsGameChecker OnlineChecker { get; private set; }

public Settings Settings { get; set; }

public SoundViewModel Plimper { get; set; }
public SoundViewModel Plimper { get; set; }

public Logger Logger { get; private set; }

#endregion

Expand Down
4 changes: 2 additions & 2 deletions WarframeMarketClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
11 changes: 1 addition & 10 deletions WarframeMarketClient/ViewModel/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Settings: INotifyPropertyChanged
{


#region properties
#region Properties

private SaveLoadFile saver = new SaveLoadFile();

Expand Down Expand Up @@ -88,15 +88,6 @@ public double Volume
set { volume = value;ApplicationState.getInstance().Plimper?.SetVolume(value); OnPropertyChanged(nameof(ChoosenSoundFile)); SaveSettings(); }
}


private bool updateAvailable;

public bool UpdateAvailable
{
get { return updateAvailable; }
set { updateAvailable = value; OnPropertyChanged(nameof(UpdateAvailable)); }
}

#endregion

public void SaveSettings() // also SettingsChanged
Expand Down

0 comments on commit d9c8f2b

Please sign in to comment.