void partialUpdate(object sender, System.IO.FileSystemEventArgs e) { lock (updateLock) { quitComplete = false; RootShare[] shares = App.fileListDatabase.getRootShares(); string path = e.FullPath.Replace('\\', '/'); SystemLog.addEntry("Partial filesystem update to " + path.Replace('/', System.IO.Path.DirectorySeparatorChar)); bool isFolder = System.IO.Directory.Exists(path); if (!isFolder) { path = path.Substring(0, path.LastIndexOf('/') + 1); isFolder = System.IO.Directory.Exists(path); } if (isFolder) { System.Threading.Thread t = new System.Threading.Thread(delegate() { foreach (RootShare r in shares) { if (r != null) { if (quitComplete) { return; } if (path.StartsWith(r.fullPath + "/")) { string remaining = path.Replace(System.IO.Path.DirectorySeparatorChar, '/').Substring(r.fullPath.Length + 1); FSListing f = getFSListing("/" + (r.name + "/" + remaining).Trim('/'), true); if (f is Folder) { deleteFolder((Folder)f, false); loadFolder((Folder)f, false, path); //TODO: Update size of everything above this folder } } } } doSave(); if (updateComplete != null) { updateComplete(); } }); t.IsBackground = true; t.Name = "Partial file list update thread"; t.Start(); } } }
public string getFullPath(FSListing item) { string output = item.name; while (item != null) { item = getFolder(item.parentId); output = item.name + "/" + output; if (item.parentId == 0) { break; } } return(output); }
ulong loadFolder(Folder f, bool urgent, string realLocation) { if (!System.IO.Directory.Exists(realLocation)) { return(0); //no such folder } ulong total = 0; wait(urgent); System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(realLocation); lock (toSave) toSave["FSListing " + f.id.ToString()] = f; //save it once here in case the user exits halfway through try { d.GetDirectories(); } catch { return(0); } Folder[] folderChildren = new Folder[d.GetDirectories().Length]; File[] fileChildren = new File[d.GetFiles().Length]; int fi = 0; try { foreach (System.IO.FileInfo z in d.GetFiles()) { if (quitting) { return(0); } wait(urgent); File output = new File(); output.id = App.fileListDatabase.allocateId(); output.name = z.Name; output.parentId = f.id; output.size = (ulong)z.Length; output.lastModified = z.LastWriteTimeUtc.Ticks; output.isFolder = false; total += output.size; fileChildren[fi] = output; fi++; lock (toSave) toSave["FSListing " + output.id.ToString()] = output; } fi = 0; foreach (System.IO.DirectoryInfo z in d.GetDirectories()) { if (quitting) { return(0); } wait(urgent); Folder output = new Folder(); output.id = App.fileListDatabase.allocateId(); output.name = z.Name; output.parentId = f.id; output.size = loadFolder(output, urgent, realLocation + "/" + z.Name); output.lastModified = z.LastWriteTimeUtc.Ticks; output.isFolder = true; total += output.size; folderChildren[fi] = output; fi++; lock (toSave) toSave["FSListing " + output.id.ToString()] = output; } } catch (System.IO.IOException) { return(0); } FSListing x = new FSListing(); f.fileIds = new ulong[fileChildren.Length]; for (int i = 0; i < f.fileIds.Length; i++) { f.fileIds[i] = fileChildren[i].id; } f.folderIds = new ulong[folderChildren.Length]; for (int i = 0; i < f.folderIds.Length; i++) { f.folderIds[i] = folderChildren[i].id; } f.lastModified = d.LastWriteTimeUtc.Ticks; if (quitting) { deleteFolder(f, true); return(0); } lock (toSave) toSave["FSListing " + f.id.ToString()] = f; return(total); }