Skip to content

Commit

Permalink
final changes and code organization
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec committed Dec 11, 2016
1 parent 9324034 commit b00a3cd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 86 deletions.
1 change: 0 additions & 1 deletion ARMA FOV Changer/Field of Views.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Ratios.cs" />
<Compile Include="Splash.xaml.cs">
<DependentUpon>Splash.xaml</DependentUpon>
</Compile>
Expand Down
12 changes: 6 additions & 6 deletions ARMA FOV Changer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</Menu>
</DockPanel>
<Separator Margin="10,154,14,249" Grid.ColumnSpan="2"/>
<TextBox x:Name="DesiredFovLeftTextBox" HorizontalAlignment="Left" Height="23" Margin="77,194,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1"/>
<TextBox x:Name="DesiredFovTopTextBox" HorizontalAlignment="Left" Height="23" Margin="77,167,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1"/>
<TextBox x:Name="DesiredFovLeftTextBox" HorizontalAlignment="Left" Height="23" Margin="77,198,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1"/>
<TextBox x:Name="DesiredFovTopTextBox" HorizontalAlignment="Left" Height="23" Margin="77,171,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1"/>
<Label x:Name="currentLabel" Content="Current" Height="27" VerticalAlignment="Top" Margin="132,127,10,0"/>
<Label x:Name="fovSliderLabel" Content="Desired FOV" Height="27" VerticalAlignment="Top" Margin="62,26,45,0" HorizontalContentAlignment="Center" Grid.Column="1"/>
<Label x:Name="fovLabel" Content="" Height="28" VerticalAlignment="Center" Margin="78,55,60,333" HorizontalAlignment="Center" Width="72" HorizontalContentAlignment="Center" Grid.Column="1" FontSize="14"/>
Expand All @@ -46,12 +46,12 @@
<Label x:Name="newLabel" Content="New" Height="27" VerticalAlignment="Top" Margin="77,127,87,0" Grid.Column="1"/>
<Label x:Name="uiTopLeftXLabel" Content="uiTopLeftX:" HorizontalAlignment="Left" Margin="29,228,0,0" VerticalAlignment="Top" Width="71" IsEnabled="False"/>
<Label x:Name="uiTopLeftYLabel" Content="uiTopLeftY:" HorizontalAlignment="Left" Margin="29,256,0,0" VerticalAlignment="Top" Width="71" IsEnabled="False"/>
<TextBox x:Name="uiTopLeftXTextBox" HorizontalAlignment="Left" Height="23" Margin="77,229,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<TextBox x:Name="uiTopLeftYTextBox" HorizontalAlignment="Left" Height="23" Margin="77,256,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<TextBox x:Name="uiTopLeftXTextBox" HorizontalAlignment="Left" Height="23" Margin="77,233,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<TextBox x:Name="uiTopLeftYTextBox" HorizontalAlignment="Left" Height="23" Margin="77,260,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<Label x:Name="uiBottomRightXLabel" Content="uiBottomRightX:" HorizontalAlignment="Left" Margin="29,293,0,0" VerticalAlignment="Top" Width="101" IsEnabled="False"/>
<Label x:Name="uiBottomRightYLabel" Content="uiBottomRightY:" HorizontalAlignment="Left" Margin="29,321,0,0" VerticalAlignment="Top" Width="101" IsEnabled="False"/>
<TextBox x:Name="uiBottomRightXTextBox" HorizontalAlignment="Left" Height="23" Margin="77,294,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<TextBox x:Name="uiBottomRightYTextBox" HorizontalAlignment="Left" Height="23" Margin="77,321,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<TextBox x:Name="uiBottomRightXTextBox" HorizontalAlignment="Left" Height="23" Margin="77,298,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<TextBox x:Name="uiBottomRightYTextBox" HorizontalAlignment="Left" Height="23" Margin="77,325,0,0" Text="" VerticalAlignment="Top" Width="82" Grid.Column="1" IsEnabled="False"/>
<Label x:Name="uiTopLeftXLabel_Copy2" HorizontalAlignment="Left" Height="23" Margin="131,228,0,0" Content="" VerticalAlignment="Top" Width="90"/>
<Label x:Name="uiTopLeftYLabel_Copy2" HorizontalAlignment="Left" Height="23" Margin="131,256,0,0" Content="" VerticalAlignment="Top" Width="89"/>
<Label x:Name="uiBottomRightXLabel_Copy2" HorizontalAlignment="Left" Height="23" Margin="131,293,0,0" Content="" VerticalAlignment="Top" Width="86"/>
Expand Down
156 changes: 77 additions & 79 deletions ARMA FOV Changer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void LoadProfile()
profileName = profilePath.Substring(cwSlashIdx + 1, profNameLengthCW - 1);
fovSlider.IsEnabled = false;
fovSlider.ToolTip = "Disabled for Cold War Assault";
fovLabel.Content = null;
fovLabel.Content = "auto";
}
else
{
Expand Down Expand Up @@ -244,66 +244,6 @@ private void LoadProfile()
refreshMath();
}

private static int GetGreatestCommonDivisor(int a, int b)
{
return b == 0 ? a : GetGreatestCommonDivisor(b, a % b);
}

private static async Task<int> CheckForUpdate()
{
//Nkosi Note: Always use asynchronous versions of network and IO methods.

//Check for version updates
var client = new HttpClient();
client.Timeout = new TimeSpan(0, 0, 0, 10);
try
{
// Open the text file using a stream reader
using (Stream stream = await client.GetStreamAsync("http://textuploader.com/d5ivh/raw"))
{
System.Version current = Assembly.GetExecutingAssembly().GetName().Version;
StreamReader reader = new StreamReader(stream);
latest = System.Version.Parse(reader.ReadLine());

List<string> newFiles = new List<string>();

while (!reader.EndOfStream)
{
newFiles.Add(await reader.ReadLineAsync());
}

for (int i = 0; i < newFiles.Count; i++)
{
if (i == 0)
fileParams += newFiles[i];
else
fileParams += " " + newFiles[i];
}

if (latest > current)
{
MessageBoxResult answer = MessageBox.Show("A new version of Field of Views is available!\n\nCurrent Version " + current + "\nLatest Version " + latest + "\n\nUpdate now?", "Field of Views Update", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (answer == MessageBoxResult.Yes)
{
//Update is available, and user wants to update. Requires app to close.
return 2;
}
//Update is available, but user chose not to update just yet.
return 1;
}
}
//No update available.
return 0;
}
catch (Exception m)
{
//MessageBox.Show("Failed to check for update.\n" + m.Message,"Error", MessageBoxButtons.OK, MessageBoxImage.Error);
return 0;
}
}

#region Object Click Events

private void saveButton_Click(object sender, RoutedEventArgs e)
{
// Overwrite fov values.
Expand Down Expand Up @@ -346,24 +286,6 @@ private void saveButton_Click(object sender, RoutedEventArgs e)

MessageBox.Show("Settings Updated!", "Success!", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void GitMenuItem_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://github.com/rex706/ARMA-FOV-Changer/");
}
private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
{
Close();
}

#endregion

private void fovSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if(heightTextBox != null && widthTextBox != null && heightTextBox.Text.Length > 2 && widthTextBox.Text.Length > 2)
refreshMath();
else
Console.WriteLine("Not enough input!");
}

private void refreshMath()
{
Expand Down Expand Up @@ -542,6 +464,59 @@ private void refreshMath()
}
}

private static async Task<int> CheckForUpdate()
{
//Nkosi Note: Always use asynchronous versions of network and IO methods.

//Check for version updates
var client = new HttpClient();
client.Timeout = new TimeSpan(0, 0, 0, 10);
try
{
// Open the text file using a stream reader
using (Stream stream = await client.GetStreamAsync("http://textuploader.com/d5ivh/raw"))
{
System.Version current = Assembly.GetExecutingAssembly().GetName().Version;
StreamReader reader = new StreamReader(stream);
latest = System.Version.Parse(reader.ReadLine());

List<string> newFiles = new List<string>();

while (!reader.EndOfStream)
{
newFiles.Add(await reader.ReadLineAsync());
}

for (int i = 0; i < newFiles.Count; i++)
{
if (i == 0)
fileParams += newFiles[i];
else
fileParams += " " + newFiles[i];
}

if (latest > current)
{
MessageBoxResult answer = MessageBox.Show("A new version of Field of Views is available!\n\nCurrent Version " + current + "\nLatest Version " + latest + "\n\nUpdate now?", "Field of Views Update", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (answer == MessageBoxResult.Yes)
{
//Update is available, and user wants to update. Requires app to close.
return 2;
}
//Update is available, but user chose not to update just yet.
return 1;
}
}
//No update available.
return 0;
}
catch (Exception m)
{
//MessageBox.Show("Failed to check for update.\n" + m.Message,"Error", MessageBoxButtons.OK, MessageBoxImage.Error);
return 0;
}
}

private void ProfileMenuItem_Click(object sender, RoutedEventArgs e)
{
fovSlider.IsEnabled = true;
Expand Down Expand Up @@ -573,6 +548,14 @@ private void ProfileMenuItem_Click(object sender, RoutedEventArgs e)
refreshMath();
}

private void fovSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (heightTextBox != null && widthTextBox != null && heightTextBox.Text.Length > 2 && widthTextBox.Text.Length > 2)
refreshMath();
else
Console.WriteLine("Not enough input!");
}

private void widthTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
if (Regex.IsMatch(widthTextBox.Text, @"^\d+$") && widthTextBox.Text.Length > 2 && Regex.IsMatch(widthTextBox.Text, @"^\d+$") && heightTextBox.Text.Length > 2)
Expand All @@ -584,5 +567,20 @@ private void heightTextBox_TextChanged(object sender, System.Windows.Controls.Te
if (Regex.IsMatch(widthTextBox.Text, @"^\d+$") && heightTextBox.Text.Length > 2 && Regex.IsMatch(widthTextBox.Text, @"^\d+$") && widthTextBox.Text.Length > 2)
refreshMath();
}

private static int GetGreatestCommonDivisor(int a, int b)
{
return b == 0 ? a : GetGreatestCommonDivisor(b, a % b);
}

private void GitMenuItem_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://github.com/rex706/ARMA-FOV-Changer/");
}

private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

0 comments on commit b00a3cd

Please sign in to comment.