Commits

HexRx committed b72d25f

Remove old configuration class

  • Participants
  • Parent commits 026e402

Comments (0)

Files changed (1)

File KPDataSave/Config.cs

-/*
-    KPDataSave - KeePass plugin which saves database in Dropbox service
-    Copyright (C) 2011 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
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-using KeePass.Plugins;
-
-namespace KPDataSave
-{
-    public static class Config
-    {
-        // Ключ под которым сохраняем в конфигах
-        private static string key = "KPDataSave";
-        // User data
-        private static AccountState acc;
-
-        // Сохраняем значения токенов и email
-        public static void SaveAccountState(IPluginHost host, string token, string secret)
-        {
-            // Сохраняем данные в памяти
-            acc.Token = token;
-            acc.Secret = secret;
-            // Пишем в конфиг
-            host.CustomConfig.SetString(key, ToSString(token, secret));
-        }
-
-        // Получение данных аккаунта
-        public static AccountState GetAccountState(IPluginHost host)
-        {
-            if (acc.Token != null)
-                return acc;
-            string state = host.CustomConfig.GetString(key);
-            // Если есть запись, но она пустая
-            if (state.Length == 0)
-                throw new NullReferenceException();
-            // Токены
-            string[] tokens = ToDString(state);
-            acc.Token = tokens[0];
-            acc.Secret = tokens[1];
-            return acc;
-        }
-
-        // Удаление инфомации об аккаунте
-        public static void RemoveAccountState(IPluginHost host)
-        {
-            // Чистим в памяти
-            acc = new AccountState();
-            // Чистим в конфигах
-            host.CustomConfig.SetString(key, "");
-        }
-
-        // Проверка существования записи в конфигах
-        /*public static bool IsAccountState(IPluginHost host)
-        {
-            if (acc.Token != null)
-                return true;
-            string state = host.CustomConfig.GetString(key);
-            if (state == null)
-                return false;
-            return true;
-        }*/
-
-        // Две строки в одну
-        private static string ToSString(string str1, string str2)
-        {
-            // Две строки должны быть одинаковой длинны
-            if (str1.Length != str2.Length)
-                throw new PlgxException("String length not equal");
-            char[] arr_out = new char[str1.Length * 2];
-            int[] stri = new int[2];
-            for (int i = 0; i < str1.Length * 2; i++)
-            {
-                if (i % 2 == 0)
-                {
-                    arr_out[i] = str1[stri[0]];
-                    stri[0]++;
-                }
-                else
-                {
-                    arr_out[i] = str2[stri[1]];
-                    stri[1]++;
-                }
-            }
-            return new String(arr_out);
-        }
-
-        // Одна строка => две
-        private static string[] ToDString(string str)
-        {
-            char[] arr1 = new char[str.Length / 2];
-            char[] arr2 = new char[str.Length / 2];
-            int[] stri = new int[2];
-            for (int i = 0; i < str.Length; i++)
-            {
-                if (i % 2 == 0)
-                {
-                    arr1[stri[0]] = str[i];
-                    stri[0]++;
-                }
-                else
-                {
-                    arr2[stri[1]] = str[i];
-                    stri[1]++;
-                }
-            }
-            // Возвращаем две строки
-            return new String[2] { new String(arr1), new String(arr2) };
-        }
-    }
-}