using System.Linq.Expressions;
using System.Net;
using System.Reflection;
+using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Forms;
+using System.Windows.Interop;
using Caliburn.Micro;
using Hardcodet.Wpf.TaskbarNotification;
using Pithos.Client.WPF.Configuration;
using Pithos.Core;
using Pithos.Interfaces;
-
+using IWin32Window = System.Windows.Forms.IWin32Window;
using Screen = Caliburn.Micro.Screen;
namespace Pithos.Client.WPF
private IEventAggregator _events;
- public PithosSettings Settings { get; set; }
+ private PithosSettings _settings;
+ public PithosSettings Settings
+ {
+ get { return _settings; }
+ set
+ {
+ _settings = value;
+ foreach (var account in _settings.Accounts.Where(account=>account.IsActive))
+ {
+ if (String.IsNullOrWhiteSpace(account.RootPath))
+ {
+ account.RootPath = _settings.PithosPath;
+ _settings.Save();
+ }
+ }
+ NotifyOfPropertyChange(()=>Settings);
+ }
+ }
- public PithosMonitor Monitor { get; private set; }
+ private Dictionary<string,PithosMonitor> _monitors=new Dictionary<string, PithosMonitor>();
+ public Dictionary<string, PithosMonitor> Monitors
+ {
+ get { return _monitors; }
+ }
- public TaskbarViewModel Taskbar { get; set; }
+ private TaskbarViewModel _taskbar;
+ public TaskbarViewModel Taskbar
+ {
+ get { return _taskbar; }
+ set
+ {
+ _taskbar = value;
+ }
+ }
//ShellExtensionController _extensionController=new ShellExtensionController();
[ImportingConstructor]
- public PreferencesViewModel(IEventAggregator events, TaskbarViewModel taskbar, PithosSettings settings, PithosMonitor monitor)
+ public PreferencesViewModel(IEventAggregator events, TaskbarViewModel taskbar, PithosSettings settings)
{
_events = events;
_events.Subscribe(this);
Taskbar=taskbar;
Taskbar.Parent = this;
- Settings=settings;
- Monitor=monitor;
+ Settings=settings;
Taskbar.UsageMessage = "Using 15% of 50 GB";
- Taskbar.RecentFiles.AddRange(new[]
- {
- new FileEntry{FileName="Moo",FullPath=@"e:\Pithos\moo"} ,
- new FileEntry{FileName="Mee",FullPath=@"e:\Pithos\mee"}
- });
Taskbar.StatusMessage = "In Synch";
}
if (String.IsNullOrWhiteSpace(activeAccount.AccountName))
return;
- Monitor.ApiKey = activeAccount.ApiKey;
- Monitor.UserName = activeAccount.AccountName;
- Monitor.UsePithos = activeAccount.UsePithos;
+ var monitor = Monitors[activeAccount.AccountName];
+ monitor.ApiKey = activeAccount.ApiKey;
+ monitor.UserName = activeAccount.AccountName;
+ monitor.UsePithos = activeAccount.UsePithos;
- Monitor.Start();
+ monitor.Start();
}
public void ChangePithosFolder()
public void RefreshOverlays()
{
- this.Monitor.Workflow.RaiseChangeNotification(Settings.PithosPath);
+ string path=Settings.PithosPath;
+ if (String.IsNullOrWhiteSpace(path))
+ throw new ArgumentNullException("path", "The path parameter must not be emtpy");
+
+ if (!Directory.Exists(path) && !File.Exists(path))
+ throw new FileNotFoundException("The specified file or path does not exist", path);
+
+
+ IntPtr pathPointer = Marshal.StringToCoTaskMemAuto(path);
+
+ try
+ {
+ NativeMethods.SHChangeNotify(HChangeNotifyEventID.SHCNE_UPDATEITEM,
+ HChangeNotifyFlags.SHCNF_PATHW | HChangeNotifyFlags.SHCNF_FLUSHNOWAIT,
+ pathPointer, IntPtr.Zero);
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(pathPointer);
+ }
+
}
#endregion
return Settings.Accounts[SelectedAccountIndex];
return null;
}
-/*
- set
- {
- _currentAccount = value;
- }
-*/
+
}
tv.TaskbarView.ShowBalloonTip(notification.Title, notification.Message, icon);
}
+
+ public void MoveAccountFolder()
+ {
+
+ using (var dlg = new FolderBrowserDialog())
+ {
+ var currentFolder = CurrentAccount.RootPath;
+ dlg.SelectedPath = currentFolder;
+ //Ask the user to select a folder
+ //Note: We need a parent window here, which we retrieve with GetView
+ var view = (Window)GetView();
+ if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view)))
+ return;
+
+ var newPath= dlg.SelectedPath;
+ //Find the account's monitor and stop it
+ var monitor = Monitors[CurrentAccount.AccountName];
+ monitor.Stop();
+
+ var oldPath = monitor.RootPath;
+ //The old directory may not exist eg. if we create an account for the first time
+ if (Directory.Exists(oldPath))
+ {
+ //If it does, do the move
+ Directory.Move(oldPath, newPath);
+ //We also need to change the path of the existing file states
+ monitor.MoveFileStates(oldPath, newPath);
+ }
+ //Replace the old rootpath with the new
+ CurrentAccount.RootPath = newPath;
+ //TODO: This will save all settings changes. Too coarse grained, need to fix at a later date
+ Settings.Save();
+ //And start the monitor on the new RootPath
+ monitor.RootPath = newPath;
+ monitor.Start();
+ //Finally, notify that the Settings, CurrentAccount have changed
+ NotifyOfPropertyChange(() => CurrentAccount);
+ NotifyOfPropertyChange(() => Settings);
+
+ }
+ }
}
}