コード例 #1
0
ファイル: FileList.cs プロジェクト: arran4/Dimension
        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);
        }
コード例 #2
0
ファイル: FileList.cs プロジェクト: arran4/Dimension
        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();
        }