Beispiel #1
0
        public bool WriteTree()
        {
            string configFile = FilesAndFolders.GetConfigPath(createFolder: true);

            var sDict = ExplicitPaths.ToSortedDictionary();

            var config = new VaultEagleConfig();

            try
            {
                config = ReadConfig(VaultName, VaultURI);
            }
            catch (Exception) { }

            string vaultId = GetVaultId(VaultName, VaultURI);

            config.Vaults[vaultId] = sDict;

            var jsonSettings = new JsonSerializerSettings()
            {
                Converters = new[] { new StringEnumConverter() }
            };
            var json = JsonConvert.SerializeObject(config, Formatting.Indented, jsonSettings);

            try
            {
                using (var writer = new StreamWriter(System.IO.File.Open(configFile, FileMode.Create, FileAccess.Write)))
                    writer.WriteLine(json);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public static SynchronizationTree ReadTree(string vaultName, string vaultURI, bool tryHarder = false)
        {
            var newTree = new SynchronizationTree(vaultName, vaultURI);

            string           vaultId = GetVaultId(vaultName, vaultURI);
            VaultEagleConfig config  = ReadConfig(vaultName, vaultURI);

            newTree.Config = config;
            var treeByVaultMap = config.Vaults;

            try
            {
                if (!treeByVaultMap.ContainsKey(vaultId))
                {
                    if (tryHarder)
                    {
                        vaultId = TryToFindMovedOrRenamedVaultId(vaultName, vaultURI, treeByVaultMap) ?? vaultId;
                    }
                }
            }
            catch (Exception) { }
            if (treeByVaultMap.ContainsKey(vaultId))
            {
                newTree.ExplicitPaths = treeByVaultMap[vaultId].ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase);
            }

            return(newTree);
        }