public RootShare[] getRootShares() { int numShares = getInt(App.settings.settings, "Root Share Count", 0); RootShare[] output = new RootShare[numShares]; for (int i = 0; i < numShares; i++) { output[i] = getObject <Model.RootShare>(App.settings.settings, "Root Share " + i.ToString()); } return(output); }
void updateRootShare(RootShare f, bool urgent) { lock (toSave) toSave.Clear(); if (quitting) { return; } f.id = App.fileListDatabase.allocateId(); ulong size = 0; SystemLog.addEntry("Updating root share " + f.fullPath.Replace('/', System.IO.Path.DirectorySeparatorChar) + "..."); sw = new System.Diagnostics.Stopwatch(); sw.Start(); string path = ""; path = f.fullPath; bool invalidated = false; System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(path); if (d.LastWriteTimeUtc.Ticks != f.lastModified) { invalidated = true; } string s = ""; try { if (d.GetFiles().Length + d.GetDirectories().Length != f.folderIds.Length + f.fileIds.Length) { invalidated = true; } foreach (System.IO.FileInfo i in d.GetFiles()) { s += i.Name + "|" + i.Length.ToString() + "|" + i.LastWriteTimeUtc.Ticks.ToString() + Environment.NewLine; wait(urgent); } foreach (System.IO.DirectoryInfo i in d.GetDirectories()) { s += i.Name + "|" + i.LastWriteTimeUtc.Ticks.ToString() + Environment.NewLine; wait(urgent); } } catch (System.IO.IOException) { return; } string s2 = ""; foreach (ulong id in f.fileIds) { File i = App.fileListDatabase.getObject <File>(App.fileListDatabase.fileList, "FSListing " + id.ToString()); if (i != null) { size += i.size; s2 += i.name + "|" + i.size + "|" + i.lastModified.ToString() + Environment.NewLine; } wait(urgent); } foreach (ulong id in f.folderIds) { Folder i = App.fileListDatabase.getObject <Folder>(App.fileListDatabase.fileList, "FSListing " + id.ToString()); if (i != null) { size += i.size; s2 += i.name + "|" + i.lastModified.ToString() + Environment.NewLine; } wait(urgent); } if (s != s2) { invalidated = true; } if (invalidated) { deleteFolder(f, urgent); size = loadFolder(f, urgent, path); f.size = size; lock (toSave) toSave["FSListing " + f.id] = f; if (!quitting) { App.fileListDatabase.setObject(App.settings.settings, "Root Share " + f.index.ToString(), f); doSave(); } } sw.Stop(); sw.Reset(); }