Skip to content

Commit

Permalink
WindowsStore: App configuration provider now working.
Browse files Browse the repository at this point in the history
Related to issue #424.
  • Loading branch information
ycastonguay committed Oct 15, 2013
1 parent 7c8c636 commit b028391
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 67 deletions.
Expand Up @@ -25,30 +25,30 @@ namespace MPfm.MVP.Config
/// <summary>
/// Singleton containing all application settings.
/// </summary>
public class AppConfig
public class AppConfigManager
{
private readonly IAppConfigProvider _provider;
public RootAppConfig Root { get; private set; }

#region Singleton

private static AppConfig instance;
private static AppConfigManager instance;
/// <summary>
/// AppConfig instance.
/// AppConfigManager instance.
/// </summary>
public static AppConfig Instance
public static AppConfigManager Instance
{
get
{
if(instance == null)
instance = new AppConfig();
instance = new AppConfigManager();
return instance;
}
}

#endregion

public AppConfig()
public AppConfigManager()
{
_provider = Bootstrapper.GetContainer().Resolve<IAppConfigProvider>();
Root = new RootAppConfig();
Expand Down
4 changes: 2 additions & 2 deletions MPfm/MPfm.MVP/Config/AudioAppConfig.cs
Expand Up @@ -22,7 +22,7 @@ namespace MPfm.MVP.Config
/// <summary>
/// Class containing all audio settings for MPfm.
/// </summary>
public class AudioAppConfig
public class AudioAppConfig : IAppConfig
{
public Device AudioDevice { get; set; }
public int SampleRate { get; set; }
Expand All @@ -38,6 +38,6 @@ public AudioAppConfig()
SampleRate = 44100;
Volume = 1;
BufferSize = 100;
}
}
}
}
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Config/ControlsAppConfig.cs
Expand Up @@ -20,7 +20,7 @@ namespace MPfm.MVP.Config
/// <summary>
/// Class containing all control settings for MPfm.
/// </summary>
public class ControlsAppConfig
public class ControlsAppConfig : IAppConfig
{
public TableViewAppConfig TableViewAppSongBrowser { get; set; }
public TableViewAppConfig TableViewAppPlaylistBrowser { get; set; }
Expand Down
28 changes: 28 additions & 0 deletions MPfm/MPfm.MVP/Config/IAppConfig.cs
@@ -0,0 +1,28 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using MPfm.MVP.Bootstrap;
using MPfm.MVP.Config.Providers;
using MPfm.MVP.Helpers;
using MPfm.Sound.AudioFiles;

namespace MPfm.MVP.Config
{
public interface IAppConfig
{
}
}
8 changes: 4 additions & 4 deletions MPfm/MPfm.MVP/Config/Providers/XmlAppConfigProvider.cs
@@ -1,4 +1,4 @@
// Copyright © 2011-2013 Yanick Castonguay
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
Expand Down Expand Up @@ -28,7 +28,7 @@ public class XmlAppConfigProvider : IAppConfigProvider
/// Loads application settings from file.
/// </summary>
/// <param name="filePath">Configuration file path</param>
/// <returns>AppConfig object</returns>
/// <returns>AppConfigManager object</returns>
public RootAppConfig Load(string filePath)
{
if (!File.Exists(filePath))
Expand All @@ -42,10 +42,10 @@ public RootAppConfig Load(string filePath)
}

/// <summary>
/// Saves AppConfig to file.
/// Saves AppConfigManager to file.
/// </summary>
/// <param name="filePath">Configuration file path</param>
/// <param name="config">AppConfig object</param>
/// <param name="config">AppConfigManager object</param>
public void Save(string filePath, RootAppConfig config)
{
XmlSerializer serializer = new XmlSerializer(typeof(RootAppConfig));
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Config/RootAppConfig.cs
Expand Up @@ -22,7 +22,7 @@

namespace MPfm.MVP.Config
{
public class RootAppConfig
public class RootAppConfig : IAppConfig
{
public bool IsFirstRun { get; set; }
public bool ShowTooltips { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Config/TableViewAppConfig.cs
Expand Up @@ -22,7 +22,7 @@ namespace MPfm.MVP.Config
/// <summary>
/// Class containing all table view settings for MPfm.
/// </summary>
public class TableViewAppConfig
public class TableViewAppConfig : IAppConfig
{
public List<TableViewColumnAppConfig> Columns { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Config/TableViewColumnAppConfig.cs
Expand Up @@ -20,7 +20,7 @@ namespace MPfm.MVP.Config
/// <summary>
/// Class containing settings for a single table view column for MPfm.
/// </summary>
public class TableViewColumnAppConfig
public class TableViewColumnAppConfig : IAppConfig
{
public string FieldName { get; set; }
public string Title { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Config/WindowAppConfig.cs
Expand Up @@ -20,7 +20,7 @@ namespace MPfm.MVP.Config
/// <summary>
/// Class containing all settings for a single Window for MPfm.
/// </summary>
public class WindowAppConfig
public class WindowAppConfig : IAppConfig
{
public string Title { get; set; }
public float X { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Config/WindowsAppConfig.cs
Expand Up @@ -20,7 +20,7 @@ namespace MPfm.MVP.Config
/// <summary>
/// Class containing settings for all windows for MPfm.
/// </summary>
public class WindowsAppConfig
public class WindowsAppConfig : IAppConfig
{
public WindowAppConfig MainWindowApp { get; set; }
public WindowAppConfig PlaylistWindowApp { get; set; }
Expand Down
36 changes: 1 addition & 35 deletions MPfm/MPfm.MVP/Helpers/ConfigurationHelper.cs
@@ -1,4 +1,4 @@
// Copyright © 2011-2013 Yanick Castonguay
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
Expand Down Expand Up @@ -64,39 +64,5 @@ static ConfigurationHelper()
DatabaseFilePath = Path.Combine(HomeDirectory, "MPfm.Database.db");
LogFilePath = Path.Combine(HomeDirectory, "MPfm.Log.txt");
}

/// <summary>
/// Loads AppConfig from file.
/// </summary>
/// <param name="filePath">Configuration file path</param>
/// <returns>AppConfig object</returns>
public static AppConfig Load(string filePath)
{
#if WINDOWSSTORE
return new AppConfig();
#else
XmlSerializer deserializer = new XmlSerializer(typeof(AppConfig));
TextReader textReader = new StreamReader(filePath);
Object obj = deserializer.Deserialize(textReader);
AppConfig theme = (AppConfig)obj;
return theme;
#endif
}

/// <summary>
/// Saves AppConfig to file.
/// </summary>
/// <param name="filePath">Configuration file path</param>
/// <param name="config">AppConfig object</param>
public static void Save(string filePath, AppConfig config)
{
#if !WINDOWSSTORE
XmlSerializer serializer = new XmlSerializer(typeof(AppConfig));
TextWriter textWriter = new StreamWriter(filePath);
serializer.Serialize(textWriter, config);
textWriter.Dispose();
#endif
}
}
}

5 changes: 3 additions & 2 deletions MPfm/MPfm.MVP/MPfm.MVP.Android.csproj
Expand Up @@ -127,6 +127,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Config\AppConfigManager.cs" />
<Compile Include="Config\IAppConfig.cs" />
<Compile Include="Messages\ConnectionStatusChangedMessage.cs" />
<Compile Include="Messages\ApplicationCloseMessage.cs" />
<Compile Include="Messages\ActivateLockScreenMessage.cs" />
Expand Down Expand Up @@ -194,10 +196,9 @@
<Compile Include="Presenters\SplashPresenter.cs" />
<Compile Include="Presenters\Interfaces\ISplashPresenter.cs" />
<Compile Include="Views\ISplashView.cs" />
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\Providers\XmlAppConfigProvider.cs" />
<Compile Include="Config\Providers\IAppConfigProvider.cs" />
<Compile Include="Config\AppConfig.cs" />
<Compile Include="Config\AudioAppConfig.cs" />
<Compile Include="Config\ControlsAppConfig.cs" />
<Compile Include="Config\TableViewAppConfig.cs" />
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.MVP/MPfm.MVP.WindowsPhone.csproj
Expand Up @@ -199,9 +199,10 @@
<Compile Include="Presenters\Interfaces\ISplashPresenter.cs" />
<Compile Include="Views\ISplashView.cs" />
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\IAppConfig.cs" />
<Compile Include="Config\Providers\XmlAppConfigProvider.cs" />
<Compile Include="Config\Providers\IAppConfigProvider.cs" />
<Compile Include="Config\AppConfig.cs" />
<Compile Include="Config\AppConfigManager.cs" />
<Compile Include="Config\AudioAppConfig.cs" />
<Compile Include="Config\ControlsAppConfig.cs" />
<Compile Include="Config\TableViewAppConfig.cs" />
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.MVP/MPfm.MVP.WindowsStore.csproj
Expand Up @@ -100,6 +100,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Config\IAppConfig.cs" />
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\Providers\XmlAppConfigProvider.cs" />
<Compile Include="Config\Providers\IAppConfigProvider.cs" />
Expand Down Expand Up @@ -168,7 +169,7 @@
<Compile Include="Presenters\SplashPresenter.cs" />
<Compile Include="Presenters\Interfaces\ISplashPresenter.cs" />
<Compile Include="Views\ISplashView.cs" />
<Compile Include="Config\AppConfig.cs" />
<Compile Include="Config\AppConfigManager.cs" />
<Compile Include="Config\AudioAppConfig.cs" />
<Compile Include="Config\ControlsAppConfig.cs" />
<Compile Include="Config\TableViewAppConfig.cs" />
Expand Down
7 changes: 4 additions & 3 deletions MPfm/MPfm.MVP/MPfm.MVP.csproj
Expand Up @@ -111,6 +111,8 @@
</ProjectExtensions>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Config\AppConfigManager.cs" />
<Compile Include="Config\IAppConfig.cs" />
<Compile Include="Messages\ConnectionStatusChangedMessage.cs" />
<Compile Include="Messages\ApplicationCloseMessage.cs" />
<Compile Include="Messages\ActivateLockScreenMessage.cs" />
Expand Down Expand Up @@ -178,16 +180,15 @@
<Compile Include="Presenters\SplashPresenter.cs" />
<Compile Include="Presenters\Interfaces\ISplashPresenter.cs" />
<Compile Include="Views\ISplashView.cs" />
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\Providers\XmlAppConfigProvider.cs" />
<Compile Include="Config\Providers\IAppConfigProvider.cs" />
<Compile Include="Config\AppConfig.cs" />
<Compile Include="Config\AudioAppConfig.cs" />
<Compile Include="Config\ControlsAppConfig.cs" />
<Compile Include="Config\TableViewAppConfig.cs" />
<Compile Include="Config\TableViewColumnAppConfig.cs" />
<Compile Include="Config\WindowAppConfig.cs" />
<Compile Include="Config\WindowsAppConfig.cs" />
<Compile Include="Config\WindowsAppConfig.cs" />
<Compile Include="Services\PlayerService.cs" />
<Compile Include="Services\Interfaces\IPlayerService.cs" />
<Compile Include="Views\IPreferencesView.cs" />
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.MVP/MPfm.MVP.iOS.csproj
Expand Up @@ -238,7 +238,8 @@
<Compile Include="Config\RootAppConfig.cs" />
<Compile Include="Config\Providers\XmlAppConfigProvider.cs" />
<Compile Include="Config\Providers\IAppConfigProvider.cs" />
<Compile Include="Config\AppConfig.cs" />
<Compile Include="Config\IAppConfig.cs" />
<Compile Include="Config\AppConfigManager.cs" />
<Compile Include="Config\AudioAppConfig.cs" />
<Compile Include="Config\ControlsAppConfig.cs" />
<Compile Include="Config\TableViewAppConfig.cs" />
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Presenters/LibraryBrowserPresenter.cs
Expand Up @@ -75,7 +75,7 @@ public void BindView(ILibraryBrowserView view)
view.OnTreeNodeDoubleClicked = (entity) => { TreeNodeDoubleClicked(entity); };

// // Load configuration
// if (AppConfig.Instance.ShowTooltips)
// if (AppConfigManager.Instance.ShowTooltips)

// Refresh view (first level nodes)
view.RefreshLibraryBrowser(GetFirstLevelNodes());
Expand Down
8 changes: 4 additions & 4 deletions MPfm/MPfm.MVP/Services/InitializationService.cs
Expand Up @@ -99,8 +99,8 @@ private void CreateTraceListener()
private void CreateDirectories()
{
#if WINDOWSSTORE
var task = ApplicationData.Current.LocalFolder.CreateFolderAsync("PeakFiles", CreationCollisionOption.OpenIfExists);
var storageFolder = task.GetResults();
//var task = ApplicationData.Current.LocalFolder.CreateFolderAsync("PeakFiles", CreationCollisionOption.OpenIfExists);
//var storageFolder = task.GetResults();
#elif WINDOWS_PHONE
//
#else
Expand All @@ -115,9 +115,9 @@ private void CreateDirectories()
private void LoadConfiguration()
{
Tracing.Log("InitializationService.CreateConfiguration -- Checking for configuration file...");
AppConfig.Instance.Load();
AppConfigManager.Instance.Load();

//ConfigurationHelper.Save(ConfigurationHelper.ConfigurationFilePath, AppConfig.Instance);
//ConfigurationHelper.Save(ConfigurationHelper.ConfigurationFilePath, AppConfigManager.Instance);
//EQPreset preset = EQPresetHelper.Load("/Users/animal/Documents/test.txt");
//EQPresetHelper.Save("/Users/animal/Documents/test.txt", new EQPreset());
}
Expand Down

0 comments on commit b028391

Please sign in to comment.