HexRx avatar HexRx committed 0485f8f

Project files

Comments (0)

Files changed (3)

KPDataSave/KPDataSave.csproj

   </ItemGroup>
   <ItemGroup>
     <Compile Include="AccountState.cs" />
-    <Compile Include="Config.cs" />
-    <Compile Include="Forms\KPDataSave.cs">
+    <Compile Include="Forms\States\Accept.cs">
       <SubType>Form</SubType>
     </Compile>
-    <Compile Include="Forms\KPDataSave.designer.cs">
-      <DependentUpon>KPDataSave.cs</DependentUpon>
+    <Compile Include="Forms\AbstractForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Forms\AbstractForm.Designer.cs">
+      <DependentUpon>AbstractForm.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Forms\States\SelectFolder.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Forms\States\SignIn.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Forms\StateControl.cs" />
+    <Compile Include="Forms\States\SignOut.cs">
+      <SubType>Form</SubType>
     </Compile>
     <Compile Include="KPDataSaveExt.cs" />
     <Compile Include="Libs\7zip\Common\CRC.cs" />
     <Compile Include="Libs\DropboxAPI\Models\AccessToken.cs" />
     <Compile Include="Libs\DropboxAPI\Models\AccountInfo.cs" />
     <Compile Include="Libs\DropboxAPI\Models\APIError.cs" />
+    <Compile Include="Libs\DropboxAPI\Models\MetaData.cs" />
     <Compile Include="Libs\DropboxAPI\Models\QuotaInfo.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Properties\Resources.Designer.cs">
       <DesignTime>True</DesignTime>
       <DependentUpon>Resources.resx</DependentUpon>
     </Compile>
+    <Compile Include="Controls\TreeViewFiles.cs">
+      <SubType>Component</SubType>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
-    <EmbeddedResource Include="Forms\KPDataSave.resx">
-      <DependentUpon>KPDataSave.cs</DependentUpon>
-    </EmbeddedResource>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
   <ItemGroup>
     <Content Include="Icons\dropbox_16x16.png" />
     <Content Include="Icons\dropbox_48x48.png" />
+    <None Include="Icons\folder_16x16.png" />
     <Content Include="Libs\Newtonsoft.Json.dll" />
     <Content Include="Libs\RestSharp.dll" />
     <Content Include="Libs\RestSharpMerge.dll" />
     <Content Include="Libs\RestSharpMerge_uc.dll" />
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PostBuildEvent>cd $(TargetDir)

KPDataSave/KPDataSaveExt.cs

 /*
     KPDataSave - KeePass plugin which saves database in Dropbox service
-    Copyright (C) 2011 HexRx
+    Copyright (C) 2011-2012 HexRx
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 {
     public sealed class KPDataSaveExt : Plugin
     {
-        private IPluginHost m_host;
+        private IPluginHost _mHost;
         // Меню
-        private ToolStripSeparator tsSep;
-        private ToolStripMenuItem tsMenuItem;
+        private ToolStripSeparator _tsSep;
+        private ToolStripMenuItem _tsMenuItem;
         // Обновление плагина
         public override string UpdateUrl
         {
         public override bool Initialize(IPluginHost host)
         {
             // Динамическая загрузка сборок
-            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
+            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomainAssemblyResolve);
 
-            m_host = host;
+            _mHost = host;
 
-            ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
+            ToolStripItemCollection tsMenu = _mHost.MainWindow.ToolsMenu.DropDownItems;
             // Разделитель
-            tsSep = new ToolStripSeparator();
-            tsMenu.Add(tsSep);
+            _tsSep = new ToolStripSeparator();
+            tsMenu.Add(_tsSep);
             // Пункт меню KPDataSave
-            tsMenuItem = new ToolStripMenuItem("KPDataSave", Properties.Resources.dropbox_16x16);
-            tsMenuItem.Click += new EventHandler(tsMenuItem_Click);
-            tsMenu.Add(tsMenuItem);
+            _tsMenuItem = new ToolStripMenuItem("KPDataSave", Properties.Resources.dropbox_16x16);
+            _tsMenuItem.Click += new EventHandler(TsMenuItemClick);
+            tsMenu.Add(_tsMenuItem);
 
             // Подписываемся на открытия базы
-            m_host.MainWindow.FileOpened += new EventHandler<KeePass.Forms.FileOpenedEventArgs>(MainWindow_FileOpened);
+            _mHost.MainWindow.FileOpened += new EventHandler<KeePass.Forms.FileOpenedEventArgs>(MainWindowFileOpened);
 
             return true;
         }
 
         // Грузим сборку из ресурсов приложения
-        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
+        private static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
         {
             if (args.Name.Contains("RestSharp"))
             {
             return null;
         }
 
-        // Событие открытия базы
-        private void MainWindow_FileOpened(object sender, KeePass.Forms.FileOpenedEventArgs e)
+        // Событие открытия базы паролей
+        private void MainWindowFileOpened(object sender, KeePass.Forms.FileOpenedEventArgs e)
         {
             // Пописываемся на событие по завершению сохранения данных в файл
-            m_host.MainWindow.FileSaved += new EventHandler<KeePass.Forms.FileSavedEventArgs>(MainWindow_FileSaved);
+            _mHost.MainWindow.FileSaved += new EventHandler<KeePass.Forms.FileSavedEventArgs>(MainWindowFileSaved);
         }
 
         // Событие сохранения данных
-        private void MainWindow_FileSaved(object sender, KeePass.Forms.FileSavedEventArgs e)
+        private void MainWindowFileSaved(object sender, KeePass.Forms.FileSavedEventArgs e)
         {
             // Информация об акке
-            AccountState acc;
-            try
-            {
-                acc = Config.GetAccountState(m_host);
-            }
-            catch (NullReferenceException)
-            {
-                // Если не произведен вход под акком, выходим из этого метода
+            AccountState account = AccountState.Deserialize(_mHost);
+            if (account == null)
                 return;
-            }
+
             // Сообщение в статуc баре
-            m_host.MainWindow.SetStatusEx("Saving in Dropbox...");
+            _mHost.MainWindow.SetStatusEx("Saving in Dropbox...");
             // Отображаем прогресс бар
-            m_host.MainWindow.MainProgressBar.Visible = true;
-            m_host.MainWindow.MainProgressBar.Style = ProgressBarStyle.Marquee;
+            _mHost.MainWindow.MainProgressBar.Visible = true;
+            _mHost.MainWindow.MainProgressBar.Style = ProgressBarStyle.Marquee;
             // Блокируем окно
-            m_host.MainWindow.UIBlockInteraction(true);
+            _mHost.MainWindow.UIBlockInteraction(true);
             // Путь к файлу базы
-            string db_file = m_host.Database.IOConnectionInfo.Path;
-            DropboxClient client = new DropboxClient("hhekhlyshoqxt5s", "h0oh21e8y2seixx", acc.Token, acc.Secret);
+            string dbFile = _mHost.Database.IOConnectionInfo.Path;
+            DropboxClient client = new DropboxClient("hhekhlyshoqxt5s", "h0oh21e8y2seixx", account.Token, account.Secret);
             // Сохранение файла базы на сервере Dropbox
-            FileInfo file = new FileInfo(db_file);
+            FileInfo file = new FileInfo(dbFile);
+
             // Поток для выполнения асинхронной загрузки файла
-            new Thread(delegate() { this.UploadFileAsync(client, file); }).Start();
+            new Thread(() => UploadFileAsync(client, file, account.Path)).Start();
         }
 
         // Клик на пункте меню настроек плагина
-        void tsMenuItem_Click(object sender, EventArgs e)
+        private void TsMenuItemClick(object sender, EventArgs e)
         {
-            // Форма настроек
-            using (Forms.KPDataSave ds = new Forms.KPDataSave(m_host))
-            {
-                ds.ShowDialog();
-            }
+            // Вызываем менеджер состояний
+            new Forms.StateControl(_mHost);
         }
 
         // Завершение приложения
         public override void Terminate()
         {
-            ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
+            ToolStripItemCollection tsMenu = _mHost.MainWindow.ToolsMenu.DropDownItems;
             // Сносим пункты меню
-            tsMenu.Remove(tsSep);
-            tsMenu.Remove(tsMenuItem);
+            tsMenu.Remove(_tsSep);
+            tsMenu.Remove(_tsMenuItem);
         }
 
         // Асинхронная загрузка
-        private void UploadFileAsync(DropboxClient client, FileInfo file)
+        private void UploadFileAsync(DropboxClient client, FileInfo file, string path)
         {
             // Выполняем загрузку файла
-            if (client.UploadFile("/", file))
-                m_host.MainWindow.SetStatusEx("Dropbox save complete!");
-            else
-                m_host.MainWindow.SetStatusEx("Dropbox save error!");
+            _mHost.MainWindow.SetStatusEx(client.UploadFile(path, file)
+                                              ? "Dropbox save complete!"
+                                              : "Dropbox save error!");
             // Скрываем прогресс
-            m_host.MainWindow.MainProgressBar.Visible = false;
+            _mHost.MainWindow.MainProgressBar.Visible = false;
             // Разблокируем окно
-            m_host.MainWindow.UIBlockInteraction(false);
+            _mHost.MainWindow.UIBlockInteraction(false);
         }
     }
 }

KPDataSave/Properties/AssemblyInfo.cs

 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("HexRx")]
 [assembly: AssemblyProduct("KeePass Plugin")]
-[assembly: AssemblyCopyright("Copyright ©  2011")]
+[assembly: AssemblyCopyright("Copyright © 2011-2012")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.0.3.0")]
-[assembly: AssemblyFileVersion("0.0.3.0")]
+[assembly: AssemblyVersion("0.0.4.0")]
+[assembly: AssemblyFileVersion("0.0.4.0")]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.