-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rudolf Hardy Plutarco Aragao
committed
Mar 28, 2017
1 parent
b8cb496
commit 34e38ae
Showing
13 changed files
with
850 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<configSections> | ||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | ||
<section name="XP11SettingsTool.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> | ||
</sectionGroup> | ||
</configSections> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
<userSettings> | ||
<XP11SettingsTool.Properties.Settings> | ||
<setting name="FlyWithLuaScriptsFolder" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
</XP11SettingsTool.Properties.Settings> | ||
</userSettings> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Application x:Class="XP11SettingsTool.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace XP11SettingsTool | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
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 Microsoft.Win32; | ||
using XP11SettingsTool.Properties; | ||
|
||
namespace XP11SettingsTool | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
private IEnumerable<string> _lines; | ||
|
||
private const string FileName = "Settings.lua"; | ||
private const string FileDefaultName = "SettingsDefault.lua"; | ||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private double GetDoubleValue(string tag) | ||
{ | ||
var linha = _lines.FirstOrDefault(l => l.Contains(tag)); | ||
var value = linha.Split(',')[1].Replace(")", ""); | ||
return Convert.ToDouble(value, new CultureInfo("en")); | ||
} | ||
|
||
private bool GetBoolValue(string tag) | ||
{ | ||
var linha = _lines.FirstOrDefault(l => l.Contains(tag)); | ||
var value = linha.Split(',')[1].Replace(")", ""); | ||
return value.Trim() == "1.00"; | ||
} | ||
|
||
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject | ||
{ | ||
if (depObj != null) | ||
{ | ||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) | ||
{ | ||
DependencyObject child = VisualTreeHelper.GetChild(depObj, i); | ||
if (child != null && child is T) | ||
{ | ||
yield return (T)child; | ||
} | ||
|
||
foreach (T childOfChild in FindVisualChildren<T>(child)) | ||
{ | ||
yield return childOfChild; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void LoadValues(string filePath) | ||
{ | ||
try | ||
{ | ||
if (File.Exists(filePath)) | ||
{ | ||
_lines = File.ReadLines(filePath); | ||
|
||
foreach (CheckBox ckb in FindVisualChildren<CheckBox>(grdMain)) | ||
{ | ||
ckb.IsChecked = GetBoolValue(ckb.Tag.ToString()); | ||
} | ||
|
||
foreach (Slider sld in FindVisualChildren<Slider>(grdMain)) | ||
{ | ||
sld.Value = GetDoubleValue(sld.Tag.ToString()); | ||
} | ||
} | ||
else | ||
{ | ||
MessageBox.Show(this, "File '" + filePath + "' cannot be found. Please reinstall.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
} | ||
|
||
private void SaveFile() | ||
{ | ||
try | ||
{ | ||
foreach (CheckBox ckb in FindVisualChildren<CheckBox>(grdMain)) | ||
{ | ||
var line = _lines.FirstOrDefault(l => l.Contains(ckb.Tag.ToString())); | ||
var value = ckb.IsChecked.Value ? " 1.00)" : " 0.00)"; | ||
var newLine = line.Replace(line.Split(',')[1], value); | ||
|
||
_lines = _lines.Select(s => s == line ? newLine : s).ToArray(); | ||
} | ||
|
||
foreach (Slider sld in FindVisualChildren<Slider>(grdMain)) | ||
{ | ||
var line = _lines.FirstOrDefault(l => l.Contains(sld.Tag.ToString())); | ||
var value = " " + sld.Value.ToString("0.00", new CultureInfo("en")) + ")"; | ||
var newLine = line.Replace(line.Split(',')[1], value); | ||
|
||
_lines = _lines.Select(s => s == line ? newLine : s).ToArray(); | ||
} | ||
|
||
SaveFileDialog saveFileDialog = new SaveFileDialog(); | ||
saveFileDialog.FileName = FileName; | ||
|
||
if (Directory.Exists(Settings.Default.FlyWithLuaScriptsFolder)) | ||
saveFileDialog.InitialDirectory = Settings.Default.FlyWithLuaScriptsFolder; | ||
|
||
if (saveFileDialog.ShowDialog() == true) | ||
{ | ||
File.WriteAllLines(saveFileDialog.FileName, _lines); // Na pasta | ||
File.WriteAllLines(FileName, _lines); // Local | ||
|
||
Settings.Default.FlyWithLuaScriptsFolder = System.IO.Path.GetDirectoryName(saveFileDialog.FileName); | ||
Settings.Default.Save(); | ||
MessageBox.Show(this, "Settings saved successfully.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
} | ||
|
||
private void Window_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
if (File.Exists(FileName)) | ||
{ | ||
LoadValues(FileName); | ||
} | ||
else | ||
{ | ||
LoadValues(FileDefaultName); | ||
} | ||
} | ||
|
||
private void btnSave_Click(object sender, RoutedEventArgs e) | ||
{ | ||
SaveFile(); | ||
} | ||
|
||
private void btnDefault_Click(object sender, RoutedEventArgs e) | ||
{ | ||
MessageBoxResult result = MessageBox.Show(this, "Discard all changes and load default XP11 values?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); | ||
if (result == MessageBoxResult.Yes) | ||
{ | ||
LoadValues(FileDefaultName); | ||
} | ||
} | ||
|
||
private void btnUndo_Click(object sender, RoutedEventArgs e) | ||
{ | ||
MessageBoxResult result = MessageBox.Show(this, "Discard all current changes?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); | ||
if (result == MessageBoxResult.Yes) | ||
{ | ||
LoadValues(FileName); | ||
} | ||
} | ||
|
||
private void btnExit_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Application.Current.Shutdown(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Reflection; | ||
using System.Resources; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("XP11SettingsTool")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("XP11SettingsTool")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
//In order to begin building localizable applications, set | ||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file | ||
//inside a <PropertyGroup>. For example, if you are using US english | ||
//in your source files, set the <UICulture> to en-US. Then uncomment | ||
//the NeutralResourceLanguage attribute below. Update the "en-US" in | ||
//the line below to match the UICulture setting in the project file. | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] | ||
|
||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.