示例#1
0
        public StorageFolder Clone()
        {
            // clones everything except notes

            StorageFolder clone = new StorageFolder();

            clone.ParentUID = ParentUID;
            clone.UID = UID;
            clone.Name = Name;
            clone.Date = Date;
            clone.Flags = Flags;
            clone.Revs = Revs;

            return clone;
        }
示例#2
0
        public FolderNode AddFolderInfo(StorageFolder info, bool remote)
        {
            if (!Folders.ContainsKey(info.UID))
            {
                Folders[info.UID] = new FolderNode(View, info, this, remote);

                if (!info.IsFlagged(StorageFlags.Archived) || View.GhostsButton.Checked)
                    GuiUtils.InsertSubNode(this, Folders[info.UID]);
            }

            FolderNode folder = Folders[info.UID];

            if (!remote)
            {
                if (info.IntegratedID != 0)
                    folder.Integrated.SafeAdd(info.IntegratedID, info);
                else
                    folder.Archived.SafeAddLast(info);
            }

            return folder;
        }
示例#3
0
        public static StorageFolder Decode(G2Header root)
        {
            StorageFolder folder = new StorageFolder();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_UID:
                        folder.UID = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                        break;

                    case Packet_ParentUID:
                        folder.ParentUID = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                        break;

                    case Packet_Name:
                        folder.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Date:
                        folder.Date = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_Flags:
                        folder.Flags = (StorageFlags) BitConverter.ToUInt16(child.Data, child.PayloadPos);
                        break;

                    case Packet_Note:
                        folder.Note = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Revs:
                        folder.Revs = child.Data[child.PayloadPos];
                        break;

                    case Packet_Integrated:
                        folder.IntegratedID = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                        break;

                    case Packet_Scope:
                        folder.Scope[BitConverter.ToUInt64(child.Data, child.PayloadPos)] = BitConverter.ToInt16(child.Data, child.PayloadPos + 8);
                        break;
                }
            }

            return folder;
        }
示例#4
0
        //Nodes - contains sub-folders
        public FolderNode(StorageView view, StorageFolder folder, TreeListNode parent, bool temp)
        {
            Parent = parent; // needs to be set because some nodes (archived) aren't proper children of parents (not in Nodes list), still needed though so getPath works

            if (parent == null)
                throw new Exception("Parent set to null");

            View = view;

            Details = folder;
            Temp = temp;

            Update();
        }
示例#5
0
        private void SelectFolder(FolderNode folder)
        {
            if (folder == null)
                return;

            /*
             *
             * if (!SelectedInfo.IsFile && SelectedInfo.CurrentFolder != null)
            {
                if (SelectedInfo.CurrentFolder.Details.UID == SelectedFolder.Details.UID)
                    SelectedInfo.ShowItem(SelectedFolder, null);
                else
                    SelectedInfo.ShowDefault();
            }
             * */

            bool infoSet = false;
            string infoPath = SelectedInfo.CurrentPath;

            SelectedFolder = folder;
            folder.Selected = true;

            string dirpath = null;
            if (Working != null)
                dirpath = Working.RootPath + folder.GetPath();

            ulong selectedUID = 0;
            if (SelectedInfo.CurrentItem != null)
                selectedUID = SelectedInfo.CurrentItem.UID;

            FileListView.Items.Clear();
            FileListView.SmallImageList = FileIcons;

            // add sub folders
            if (!FoldersButton.Checked && folder.Parent.GetType() == typeof(FolderNode))
            {
                FileItem dots = new FileItem(this, new FolderNode(this, new StorageFolder(), folder.Parent, false));
                dots.Folder.Details.Name = "..";
                dots.Text = "..";

                if (string.Compare("..", infoPath, true) == 0)
                {
                    infoSet = true;
                    dots.Selected = true;
                    SelectedInfo.ShowDots();
                }

                FileListView.Items.Add(dots);
            }

            foreach (FolderNode sub in folder.Nodes)
            {
                FileItem subItem = new FileItem(this, sub);

                if (string.Compare(sub.GetPath(), infoPath, true) == 0)
                {
                    infoSet = true;
                    subItem.Selected = true;
                    SelectedInfo.ShowItem(sub, null);
                }

                FileListView.Items.Add(subItem);
            }

            // if folder unlocked, add untracked folders, mark temp
            if(folder.Details.IsFlagged(StorageFlags.Unlocked) && Directory.Exists(dirpath))
                try
                {
                    foreach (string dir in Directory.GetDirectories(dirpath))
                    {
                        string name = Path.GetFileName(dir);

                        if (name.CompareTo(".history") == 0)
                            continue;

                        if (folder.GetFolder(name) != null)
                            continue;

                        StorageFolder details = new StorageFolder();
                        details.Name = name;

                        FileItem tempFolder = new FileItem(this, new FolderNode(this, details, folder, true));

                        if (string.Compare(tempFolder.GetPath(), infoPath, true) == 0)
                        {
                            infoSet = true;
                            tempFolder.Selected = true;
                            SelectedInfo.ShowItem(tempFolder.Folder, null);
                        }

                        FileListView.Items.Add(tempFolder);
                    }
                }
                catch { }

            // add tracked files
            foreach (FileItem file in folder.Files.Values)
                if (!file.Details.IsFlagged(StorageFlags.Archived) || GhostsButton.Checked)
                {
                    if (string.Compare(file.GetPath(), infoPath, true) == 0)
                    {
                        infoSet = true;
                        file.Selected = true;
                        SelectedInfo.ShowItem(folder, file);
                    }
                    else
                        file.Selected = false;

                    FileListView.Items.Add(file);
                }

            // if folder unlocked, add untracked files, mark temp
            if (folder.Details.IsFlagged(StorageFlags.Unlocked) && Directory.Exists(dirpath))
                try
                {
                    foreach (string filepath in Directory.GetFiles(dirpath))
                    {
                        string name = Path.GetFileName(filepath);

                        if (folder.GetFile(name) != null)
                            continue;

                        StorageFile details = new StorageFile();
                        details.Name = name;
                        details.InternalSize = new FileInfo(filepath).Length;

                        FileItem tempFile = new FileItem(this, folder, details, true);

                        if (string.Compare(tempFile.GetPath(), infoPath, true) == 0)
                        {
                            infoSet = true;
                            tempFile.Selected = true;
                            SelectedInfo.ShowItem(folder, tempFile);
                        }

                        FileListView.Items.Add(tempFile);
                    }
                }
                catch { }

            UpdateListItems();

            if (!infoSet && SelectedFolder.GetPath() == infoPath)
            {
                infoSet = true;
                SelectedInfo.ShowItem(SelectedFolder, null);
            }
            if (!infoSet)
                SelectedInfo.ShowDiffs();
        }
示例#6
0
        public void ReadyChange(LocalFolder folder, StorageFolder newInfo)
        {
            Modified = true;
            PeriodicSave = true;

            folder.Modify(Core.TimeNow, newInfo);
        }
示例#7
0
        private void RefreshView()
        {
            FolderNode prevSelected = SelectedFolder;

            RootFolder = null;

            FolderTreeView.Nodes.Clear();
            FileListView.Items.Clear();

            FolderTreeView.Nodes.Add(new TreeListNode());

            // if local
            if (IsLocal)
                RootFolder = LoadWorking(FolderTreeView.virtualParent, Working.RootFolder);

            // else load from file
            else
            {
                StorageFolder root = new StorageFolder();
                root.Name = Trust.GetProjectName(ProjectID) + " Files";

                RootFolder = new FolderNode(this, root, FolderTreeView.virtualParent, false);
                FolderTreeView.Nodes.Add(RootFolder);

                OpStorage storage = Storages.GetStorage(UserID);

                if (storage != null)
                    LoadHeader(Storages.GetFilePath(storage), storage.File.Header.FileKey);
            }

            // re-diff
            foreach (ulong id in CurrentDiffs)
                ApplyDiff(id);

            if (RootFolder != null)
            {
                RootFolder.Expand();

                bool high = false, low = false;
                AnalyzeChanges(RootFolder, true, ref high, ref low);
            }

            bool showDiffs = SelectedInfo.DiffsView; // save diffs view mode here because selectFolder resets it

            // if prev == selected, this means selected wasnt updated in refresh
            if (SelectedFolder == null || prevSelected == SelectedFolder)
                SelectFolder(RootFolder);
            else
            {
                SelectedFolder.EnsureVisible();
                RefreshFileList();
            }

            if (showDiffs)
                SelectedInfo.ShowDiffs();
        }
示例#8
0
        public void Modify(DateTime time, StorageFolder newInfo)
        {
            if (Info.IsFlagged(StorageFlags.Modified))
            {
                Info = newInfo;
                Archived.SafeRemoveFirst();
                Archived.SafeAddFirst(newInfo);
            }
            else
            {
                Archived.SafeAddFirst(newInfo);
                Info = newInfo;
            }

            Info.SetFlag(StorageFlags.Modified);
            Info.Date = time.ToUniversalTime();
        }
示例#9
0
        public WorkingStorage(StorageService storages, uint project)
        {
            Storages = storages;
            Core = Storages.Core;
            Protocol = storages.Protocol;

            RootPath = Storages.GetRootPath(Core.UserID, project);
            ProjectID = project;

            StorageFolder packet = new StorageFolder();
            packet.Name = Core.Trust.GetProjectName(project) + " Files";

            RootFolder = new LocalFolder(null, packet);

            LoadWorking();
        }
示例#10
0
        public LocalFolder AddFolderInfo(StorageFolder info)
        {
            LocalFolder folder = null;

            if (!Folders.SafeTryGetValue(info.UID, out folder))
            {
                folder = new LocalFolder(this, info);
                Folders.SafeAdd(info.UID, folder);
            }

            // if this is integration info, add to integration map
            if (info.IntegratedID != 0)
                folder.Integrated.SafeAdd(info.IntegratedID, info);

            // if history info, add to files history
            else
                folder.Archived.SafeAddLast(info);

            return folder;
        }
示例#11
0
        public void AddHigherChange(ulong id, StorageFolder change)
        {
            if (!HigherChanges.ContainsKey(id))
                HigherChanges[id] = new List<StorageItem>();

            HigherChanges[id].Add(change);
        }
示例#12
0
        private LocalFolder CreateNewFolder(LocalFolder parent, string dirname )
        {
            StorageFolder info = new StorageFolder();
            LocalFolder folder = new LocalFolder(parent, info);

            info.UID = Utilities.StrongRandUInt64(Core.StrongRndGen);
            info.ParentUID = parent.Info.UID;
            info.Name = dirname;
            info.Date = Core.TimeNow.ToUniversalTime();
            info.Revs = 5;

            folder.Archived.SafeAddFirst(info);

            return folder;
        }
示例#13
0
        public LocalFolder(LocalFolder parent, StorageFolder info)
        {
            Parent = parent;

            Info = info;
        }
示例#14
0
        public void TrackFolder(string path, StorageFolder track)
        {
            string parentPath = Utilities.StripOneLevel(path);

            LocalFolder folder = GetLocalFolder(path);

            if (folder != null)
                return;

            LocalFolder parent = GetLocalFolder(parentPath);

            if (parent == null)
                return;

            folder = new LocalFolder(parent, track);
            folder.Archived.SafeAddFirst(track);
            folder.Info.SetFlag(StorageFlags.Modified);

            parent.AddFolder(folder);

            if (Directory.Exists(RootPath + parentPath + Path.DirectorySeparatorChar + folder.Info.Name))
                folder.Info.SetFlag(StorageFlags.Unlocked);

            Modified = true;
            PeriodicSave = true;

            Storages.CallFolderUpdate(ProjectID, parentPath, folder.Info.UID, WorkingChange.Created);
        }
示例#15
0
        public void ReplaceFolder(string path, StorageFolder replacement, bool setModified)
        {
            LocalFolder folder = GetLocalFolder(path);

            string oldPath = RootPath + path;

            // only create new entry for un-modified file
            if (setModified)
                ReadyChange(folder, replacement);
            else
            {
                folder.Info = replacement;
                folder.Archived.SafeAddFirst(replacement);
            }

            // rename folder on drive if it exists to match new folder
            try
            {
                if (Directory.Exists(oldPath))
                    if (Path.GetFileName(oldPath) != folder.Info.Name)
                    {
                        Directory.Move(oldPath, RootPath + folder.GetPath());
                        folder.Info.SetFlag(StorageFlags.Unlocked);
                    }
            }
            catch { }

            Storages.CallFolderUpdate(ProjectID, folder.Parent.GetPath(), folder.Info.UID, WorkingChange.Updated);
        }
示例#16
0
        public void SimCleanup()
        {
            FileMap.SafeClear();
            InternalFileMap.SafeClear();

            WorkingStorage x = Working[0];

            StorageFolder packet = new StorageFolder();
            packet.Name = Core.Trust.GetProjectName(0) + " Files";
            x.RootFolder = new LocalFolder(null, packet);

            SaveLocal(0);
        }