private static Nullable <DateTime> GetRegistryTimestamp(string CacheId) { if (!File.Exists(FilePath)) { return(null); } var root = DataFormats.LoadFromFile(FilePath); var caches = root.GetNode("caches"); if (caches == null) { Log.Write("caches == null"); return(null); } var cacheNode = caches.GetNode(CacheId); if (cacheNode == null) { return(null); } string timestamp = cacheNode.GetString("timestamp"); if (String.IsNullOrEmpty(timestamp)) { return(null); } return(DateTime.Parse(timestamp)); }
private void LoadValues(string[] args, string prefix) { var lastIndex = args.Length - 1; for (int index = 0; index <= lastIndex; index++) { var arg = args[index]; if (!arg.StartsWith(prefix)) { if (index == lastIndex) { defaultArgument = arg; return; } else { throw new Exception("Invalid argument format: " + arg); } } var temp = arg.Substring(prefix.Length).Split(new char[] { '=' }, 2); var key = temp[0]; var val = temp.Length > 1 ? temp[1] : null; if (key == "config") { if (File.Exists(val)) { var root = DataFormats.LoadFromFile(val); if (root != null) { if (root.Name == "config") { root = root["config"]; } var strings = root.Children.Select(x => $"{prefix}{x.Name}={x.Value} ").ToArray(); LoadValues(strings, prefix); } else { throw new Exception($"Error loading config file: {val}"); } } else { throw new Exception($"Could not find config file: {val}"); } } else { entries[key] = val; } } }
private static void UpdateRegistry(string CacheId, DateTime Timestamp, int Size, string WalletName) { DataNode root; if (File.Exists(FilePath)) { root = DataFormats.LoadFromFile(FilePath); } else { root = DataNode.CreateObject(); } DataNode caches; if (root.HasNode("caches")) { caches = root.GetNode("caches"); } else { caches = root.AddNode(DataNode.CreateObject("caches")); } DataNode cacheNode; if (caches.HasNode(CacheId)) { cacheNode = caches.GetNode(CacheId); } else { cacheNode = caches.AddNode(DataNode.CreateObject(CacheId)); } if (cacheNode.HasNode("timestamp")) { cacheNode.GetNode("timestamp").Value = Timestamp.ToString(); } else { cacheNode.AddField("timestamp", Timestamp.ToString()); } if (cacheNode.HasNode("size")) { cacheNode.GetNode("size").Value = Size.ToString(); } else { cacheNode.AddField("size", Size.ToString()); } if (cacheNode.HasNode("wallet-name")) { cacheNode.GetNode("wallet-name").Value = WalletName; } else { if (!String.IsNullOrEmpty(WalletName)) { cacheNode.AddField("wallet-name", WalletName); } } DataFormats.SaveToFile(FilePath, root); }