Skip to content

Commit

Permalink
Add settings backup & restore
Browse files Browse the repository at this point in the history
  • Loading branch information
medokin committed Nov 7, 2018
1 parent 9ba1281 commit eeee5e8
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


## Table of contents
<a href="https://mathewsachin.github.io/Captura/screenshots"><img src="app.png" align="right"></a>
<a href="https://github.com/medokin/soundpad-text-to-speech/blob/master/app.png"><img src="app.png" align="right"></a>

* [Requirements](#requirements)
* [Installation](#installation)
Expand Down
Binary file modified app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/TTSApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</StackPanel>

<Button x:Name="PlaySoundpadButton"
Content="Play in Soudpad"
Content="Play in Soundpad"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Width="150"
Expand Down
100 changes: 74 additions & 26 deletions src/TTSApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -38,7 +39,8 @@ public partial class MainWindow : Window

public MainWindow()
{
InitializeComponent();
InitializeComponent();
RestoreSettings();
}

public static MainWindowViewModel Model { get; set; }
Expand Down Expand Up @@ -66,7 +68,8 @@ private async Task InitializeViewModel()

private async Task InitializeSoundpad()
{
_soundpad = new Soundpad {
_soundpad = new Soundpad
{
AutoReconnect = true
};
_soundpad.StatusChanged += SoundpadOnStatusChanged;
Expand All @@ -80,14 +83,15 @@ private async Task CheckAndInstallUpdate()
UpdateSpinner.Visibility = Visibility.Visible;
VersionTextBlock.Text = "Checking for Updates...";
using (var mgr = new UpdateManager(UpdateUrl))
{
{
var update = await mgr.CheckForUpdate(true);
VersionTextBlock.Text = update.CurrentlyInstalledVersion.Version.ToString();
if (update.CurrentlyInstalledVersion.EntryAsString != update.FutureReleaseEntry.EntryAsString)
{
VersionTextBlock.Text = "Installing Updates...";
await mgr.UpdateApp();
VersionTextBlock.Text = "Updates installed. Please restart.";
BackupSettings();
}
}
}
Expand Down Expand Up @@ -213,12 +217,9 @@ private async void PlaySoundpadButton_Click(object sender, RoutedEventArgs e)
return;
}


var text = InputTextBox.Text;
if (Settings.Default.EmptyTextAfterPlay)
{
InputTextBox.Text = "";
}
if (Settings.Default.EmptyTextAfterPlay) InputTextBox.Text = "";
InputTextBox.Focus();
await Play(text);
}
Expand All @@ -234,20 +235,19 @@ private void MenuItemSettings_OnClick(object sender, RoutedEventArgs e)
settings.ShowDialog();
}

private void MenuItemAbout_OnClick(object sender, RoutedEventArgs e) {
private void MenuItemAbout_OnClick(object sender, RoutedEventArgs e)
{
var about = new AboutWindow();
about.ShowDialog();
}

private void InputTextBox_OnKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
PlaySoundpadButton_Click(sender, e);
}
if (e.Key == Key.Enter) PlaySoundpadButton_Click(sender, e);
}

private void SettingsCheckboxChanged(object sender, RoutedEventArgs e) {
private void SettingsCheckboxChanged(object sender, RoutedEventArgs e)
{
Settings.Default.Save();
}

Expand All @@ -259,20 +259,73 @@ private void ProviderHelpIcon_OnClick(object sender, RoutedEventArgs e)

private void MenuItemWebsite_OnClick(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/medokin/soundpad-text-to-speech");
Process.Start("https://github.com/medokin/soundpad-text-to-speech");
}

private void MenuItemReportAnIssue_OnClick(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/medokin/soundpad-text-to-speech/issues/new");
Process.Start("https://github.com/medokin/soundpad-text-to-speech/issues/new");
}

public void BackupSettings()
{
try
{
var settingsFile = ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
var destination = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\last.config";
File.Copy(settingsFile, destination, true);
}
catch (Exception e)
{
}
}

private void RestoreSettings()
{
//Restore settings after application update
var destFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
.FilePath;
var sourceFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\last.config";
// Check if we have settings that we need to restore
if (!File.Exists(sourceFile)) return;
// Create directory as needed
try
{
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
}
catch (Exception)
{
}

// Copy our backup file in place
try
{
File.Copy(sourceFile, destFile, true);
Settings.Default.Reload();
}
catch (Exception)
{
}

// Delete backup file
try
{
File.Delete(sourceFile);
}
catch (Exception)
{
}
}
}

public class MainWindowViewModel : INotifyPropertyChanged
{
public MainWindowViewModel()
{
}
public ITextToSpeechProvider SelectedProvider { get; set; }
public IList<ITextToSpeechProvider> ProviderList { get; set; }
public IList<IVoice> VoiceList { get; set; }
public IVoice SelectedVoice { get; set; }
public event PropertyChangedEventHandler PropertyChanged;

private void ReloadProviderList()
{
Expand All @@ -287,12 +340,6 @@ private void ReloadProviderList()
OnPropertyChanged(nameof(ProviderList));
}

public ITextToSpeechProvider SelectedProvider { get; set; }
public IList<ITextToSpeechProvider> ProviderList { get; set; }
public IList<IVoice> VoiceList { get; set; }
public IVoice SelectedVoice { get; set; }
public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
Expand Down Expand Up @@ -351,7 +398,8 @@ public async Task<ITextToSpeechProvider> DefaultProvider()


var lastUsedProvider =
ProviderList.FirstOrDefault(provider => provider.Name == Settings.Default.LastProvider && provider.IsAvailable);
ProviderList.FirstOrDefault(provider =>
provider.Name == Settings.Default.LastProvider && provider.IsAvailable);

return lastUsedProvider ?? ProviderList.First();
}
Expand Down
4 changes: 2 additions & 2 deletions src/TTSApp/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 Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.15")]
[assembly: AssemblyFileVersion("1.0.15")]
[assembly: AssemblyVersion("1.0.17")]
[assembly: AssemblyFileVersion("1.0.17")]

0 comments on commit eeee5e8

Please sign in to comment.