2018-08-29 06:11:41 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2018-08-31 02:40:48 -04:00
|
|
|
|
using System.Linq;
|
2018-11-28 16:50:42 -05:00
|
|
|
|
using System.Xml.Serialization;
|
2018-08-29 06:11:41 -04:00
|
|
|
|
using Filtration.ObjectModel.Enums;
|
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
|
|
|
|
namespace Filtration.ObjectModel.ThemeEditor
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class StringThemeComponent : ThemeComponent
|
|
|
|
|
{
|
|
|
|
|
private string _value;
|
|
|
|
|
public static ObservableCollection<string> _customSoundsAvailable;
|
|
|
|
|
|
2018-11-28 16:50:42 -05:00
|
|
|
|
private StringThemeComponent()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 06:11:41 -04:00
|
|
|
|
public StringThemeComponent(ThemeComponentType componentType, string componentName, string componentValue)
|
|
|
|
|
{
|
|
|
|
|
if (componentName == null || componentValue == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Null parameters not allowed in StringThemeComponent constructor");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentType = componentType;
|
|
|
|
|
Value = componentValue;
|
|
|
|
|
ComponentName = componentName;
|
|
|
|
|
|
|
|
|
|
if (_customSoundsAvailable == null || _customSoundsAvailable.Count < 1)
|
|
|
|
|
{
|
2018-08-31 02:40:48 -04:00
|
|
|
|
|
|
|
|
|
_customSoundsAvailable = new ObservableCollection<string>();
|
|
|
|
|
|
|
|
|
|
var poeFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\My Games\Path of Exile\";
|
2018-08-31 09:54:24 -04:00
|
|
|
|
if(System.IO.Directory.Exists(poeFolderPath))
|
2018-08-31 02:40:48 -04:00
|
|
|
|
{
|
2018-08-31 09:54:24 -04:00
|
|
|
|
var poeFolderFiles = System.IO.Directory.GetFiles(poeFolderPath).Where(
|
|
|
|
|
s => s.EndsWith(".mp3")
|
|
|
|
|
|| s.EndsWith(".wav")
|
|
|
|
|
|| s.EndsWith(".wma")
|
|
|
|
|
|| s.EndsWith(".3gp")
|
|
|
|
|
|| s.EndsWith(".aag")
|
|
|
|
|
|| s.EndsWith(".m4a")
|
|
|
|
|
|| s.EndsWith(".ogg")
|
|
|
|
|
).OrderBy(f => f);
|
|
|
|
|
|
|
|
|
|
foreach (var file in poeFolderFiles)
|
|
|
|
|
{
|
|
|
|
|
_customSoundsAvailable.Add(file.Replace(poeFolderPath, ""));
|
|
|
|
|
}
|
2018-08-31 02:40:48 -04:00
|
|
|
|
}
|
2018-08-29 06:11:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 02:40:48 -04:00
|
|
|
|
if(string.IsNullOrWhiteSpace(Value))
|
|
|
|
|
{
|
|
|
|
|
Value = _customSoundsAvailable.Count > 0 ? _customSoundsAvailable[0] : "";
|
|
|
|
|
}
|
|
|
|
|
else if (_customSoundsAvailable.IndexOf(Value) < 0)
|
2018-08-29 06:11:41 -04:00
|
|
|
|
{
|
|
|
|
|
_customSoundsAvailable.Add(Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CustomSoundFileDialogCommand = new RelayCommand(OnCustomSoundFileDialog);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 16:50:42 -05:00
|
|
|
|
[XmlIgnore]
|
2018-08-29 06:11:41 -04:00
|
|
|
|
public RelayCommand CustomSoundFileDialogCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<string> CustomSoundsAvailable => _customSoundsAvailable;
|
|
|
|
|
|
|
|
|
|
public string Value
|
|
|
|
|
{
|
2018-11-28 16:50:42 -05:00
|
|
|
|
get => _value;
|
2018-08-29 06:11:41 -04:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_value = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
_themeComponentUpdatedEventHandler?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCustomSoundFileDialog()
|
|
|
|
|
{
|
2018-11-28 16:50:42 -05:00
|
|
|
|
OpenFileDialog fileDialog = new OpenFileDialog {DefaultExt = ".mp3"};
|
|
|
|
|
var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Path of Exile\";
|
2018-08-29 06:11:41 -04:00
|
|
|
|
fileDialog.InitialDirectory = poePath;
|
|
|
|
|
|
2018-11-28 16:50:42 -05:00
|
|
|
|
bool? result = fileDialog.ShowDialog();
|
2018-08-29 06:11:41 -04:00
|
|
|
|
if (result == true)
|
|
|
|
|
{
|
|
|
|
|
var fileName = fileDialog.FileName;
|
|
|
|
|
if (fileName.StartsWith(poePath))
|
|
|
|
|
{
|
|
|
|
|
fileName = fileName.Replace(poePath, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CustomSoundsAvailable.IndexOf(fileName) < 0)
|
|
|
|
|
{
|
|
|
|
|
CustomSoundsAvailable.Add(fileName);
|
|
|
|
|
OnPropertyChanged(nameof(CustomSoundsAvailable));
|
|
|
|
|
}
|
|
|
|
|
Value = fileName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|