2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.ComponentModel.Composition;
7 using System.Diagnostics;
10 using System.IO.IsolatedStorage;
12 using System.Reflection;
13 using System.Runtime.Serialization;
15 using System.Windows.Forms;
16 using Pithos.Client.Properties;
18 using Pithos.Interfaces;
19 using Pithos.ShellExtensions;
21 namespace Pithos.Client
23 public partial class Preferences : Form
26 public IStatusChecker StatusChecker;
29 public IPithosSettings Settings;
32 bool _allowVisible; // ContextMenu's Show command used
33 bool _allowClose; // ContextMenu's Exit command used
34 bool _loadFired; // Form was shown once
38 public PithosMonitor Monitor;
42 InitializeComponent();
45 protected override void SetVisibleCore(bool value)
49 base.SetVisibleCore(value);
52 protected override void OnFormClosing(FormClosingEventArgs e)
59 base.OnFormClosing(e);
61 private void openPithosFolderToolStripMenuItem_Click(object sender, EventArgs e)
66 private void notifyIcon_DoubleClick(object sender, EventArgs e)
71 private void OpenPithosPath()
73 Process.Start(Settings.PithosPath);
77 private Dictionary<PithosStatus, StatusInfo> iconNames =new List<StatusInfo>
79 new StatusInfo(PithosStatus.InSynch, "All files up to date", "TrayInSynch"),
80 new StatusInfo(PithosStatus.Syncing, "Syncing Files", "TraySynching")
81 }.ToDictionary(s => s.Status);
83 public void UpdateStatus()
85 var pithosStatus=StatusChecker.GetPithosStatus();
87 if (iconNames.ContainsKey(pithosStatus))
89 var info= iconNames[pithosStatus];
92 notifyIcon.Icon = (Icon) Resources.ResourceManager.GetObject(info.IconName);
93 notifyIcon.Text = String.Format("Pithos 1.0\r\n{0}", info.StatusText);
94 notifyIcon.BalloonTipText = info.StatusText;
95 statusToolStripMenuItem.Text = info.StatusText;
97 if (!String.IsNullOrWhiteSpace(Settings.UserName )&&
98 !String.IsNullOrWhiteSpace(Settings.ApiKey))
103 private void btnBrowsePithosPath_Click(object sender, EventArgs e)
105 pithosFolderBrowser.SelectedPath = txtPithosPath.Text;
106 var result = pithosFolderBrowser.ShowDialog();
107 if (result == DialogResult.OK)
109 var newPath = pithosFolderBrowser.SelectedPath;
110 txtPithosPath.Text = newPath;
111 Settings.PithosPath = newPath;
116 private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
118 _allowVisible = true;
123 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
125 _allowClose = _allowVisible = true;
132 private void btnCancel_Click(object sender, EventArgs e)
138 private void btnOK_Click(object sender, EventArgs e)
144 private void btnApply_Click(object sender, EventArgs e)
149 private void DoSave()
155 private void pauseSynchingToolStripMenuItem_Click(object sender, EventArgs e)
157 Monitor.Pause = !Monitor.Pause;
158 pauseSynchingToolStripMenuItem.Text = Monitor.Pause?"Resume Syncing":"Pause Syncing";
161 private void tabAccount_Click(object sender, EventArgs e)
166 private void checkActivateExtensions_CheckedChanged(object sender, EventArgs e)
168 var box = (CheckBox) sender;
170 RegisterExtensions();
172 UnregisterExtensions();
175 private void UnregisterExtensions()
177 using (var installer = new ProjectInstaller())
179 IDictionary state = LoadState();
180 installer.Uninstall(state);
184 private void RegisterExtensions()
186 using (var installer = new ProjectInstaller())
188 IDictionary state = new Dictionary<object, object>();
189 installer.Install(state);
195 private static void SaveState(IDictionary state)
197 using(var store= IsolatedStorageFile.GetUserStoreForApplication())
198 using(var file=store.CreateFile("PithosManualInstallFile"))
200 var serializer = new NetDataContractSerializer();
201 serializer.Serialize(file,state);
205 private static IDictionary LoadState()
207 using (var store = IsolatedStorageFile.GetUserStoreForApplication())
209 if (!store.FileExists("PithosManualInstallFile"))
210 return new Dictionary<object, object>();
212 using (var file = store.OpenFile("PithosManualInstallFile", FileMode.Open))
214 var serializer = new NetDataContractSerializer();
215 var state = serializer.Deserialize(file);
216 return (IDictionary) state;