Exemplo n.º 1
0
        public StorageView(CoreUI ui, StorageService storages, ulong id, uint project)
        {
            InitializeComponent();

            UI = ui;
            Core = ui.Core;
            Storages = storages;
            Trust = Core.Trust;

            UserID = id;
            ProjectID = project;

            splitContainer1.Height = Height - toolStrip1.Height;

            if (UserID == Core.UserID)
                if (Storages.Working.ContainsKey(ProjectID))
                {
                    Working = Storages.Working[ProjectID];
                    IsLocal = true;
                }

            MenuAdd = new ToolStripMenuItem("Add to Files", StorageRes.Add, FileView_Add);
            MenuLock = new ToolStripMenuItem("Lock", StorageRes.Locked, FileView_Lock);
            MenuUnlock = new ToolStripMenuItem("Unlock", StorageRes.Unlocked, FileView_Unlock);
            MenuRestore = new ToolStripMenuItem("Restore", null, FileView_Restore);
            MenuDelete = new ToolStripMenuItem("Delete", StorageRes.Reject, FileView_Delete);
            MenuDetails = new ToolStripMenuItem("Details", StorageRes.details, FileView_Details);

            GuiUtils.SetupToolstrip(toolStrip1, new OpusColorTable());

            RescanLabel.Text = "";
            StatusLabel.Text = "";
        }
Exemplo n.º 2
0
 private void DiscardButton_Click(object sender, EventArgs e)
 {
     Working = Storages.Discard(ProjectID);
 }
Exemplo n.º 3
0
        public StorageService(OpCore core)
        {
            Core = core;
            Network = core.Network;
            Protocol = Network.Protocol;
            Store = Network.Store;
            Trust = Core.Trust;

            Core.SecondTimerEvent += Core_SecondTimer;
            Core.MinuteTimerEvent += Core_MinuteTimer;

            Network.CoreStatusChange += new StatusChange(Network_StatusChange);

            Core.Transfers.FileSearch[ServiceID, FileTypeData] += new FileSearchHandler(Transfers_DataFileSearch);
            Core.Transfers.FileRequest[ServiceID, FileTypeData] += new FileRequestHandler(Transfers_DataFileRequest);

            Core.Trust.LinkUpdate += new LinkUpdateHandler(Trust_Update);

            LocalFileKey = Core.User.Settings.FileKey;
            FileCrypt.Key = LocalFileKey;
            FileCrypt.IV = new byte[FileCrypt.IV.Length];

            string rootpath = Core.User.RootPath + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar + ServiceID.ToString() + Path.DirectorySeparatorChar;
            DataPath = rootpath + FileTypeData.ToString();
            WorkingPath = rootpath + FileTypeWorking.ToString();
            ResourcePath = rootpath + FileTypeResource.ToString();

            Directory.CreateDirectory(DataPath);
            Directory.CreateDirectory(WorkingPath);

            // clear resource files so that updates of these files work
            if (Directory.Exists(ResourcePath))
                Directory.Delete(ResourcePath, true);

            Cache = new VersionedCache(Network, ServiceID, FileTypeCache, false);

            Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired);
            Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved);
            Cache.Load();

            // load working headers
            OpStorage local = GetStorage(Core.UserID);

            foreach (uint project in Trust.LocalTrust.Links.Keys)
            {
                if (local != null)
                    LoadHeaderFile(GetWorkingPath(project), local, false, true);

                Working[project] = new WorkingStorage(this, project);

                bool doSave = false;
                foreach (ulong higher in Trust.GetAutoInheritIDs(Core.UserID, project))
                    if (Working[project].RefreshHigherChanges(higher))
                        doSave = true;

                Working[project].AutoIntegrate(doSave);
            }

            foreach (string testPath in Directory.GetFiles(DataPath))
                if (!ReferencedPaths.Contains(testPath))
                    try { File.Delete(testPath); }
                    catch { }

            ReferencedPaths.Clear();
            Loading = false;
        }
Exemplo n.º 4
0
        public WorkingStorage Discard(uint project)
        {
            if (Core.InvokeRequired)
            {
                WorkingStorage previous = null;
                Core.RunInCoreBlocked(delegate() { previous = Discard(project); });
                return previous;
            }

            if (!Working.ContainsKey(project))
                return null;

            // LockAll() to prevent unlocked discarded changes from conflicting with previous versions of
            // files when they are unlocked again by the user
            List<LockError> errors = new List<LockError>();
            Working[project].LockAll(errors);
            Working.Remove(project);

            // call unload on working
            string path = GetWorkingPath(project);
            UnloadHeaderFile(path, LocalFileKey);

            // delete working file
            try { File.Delete(path); }
            catch { };

            //loadworking
            Working[project] = new WorkingStorage(this, project);

            if (StorageUpdate != null)
                Core.RunInGuiThread(StorageUpdate, GetStorage(Core.UserID));

            return Working[project];
        }
Exemplo n.º 5
0
        void Trust_Update(OpTrust trust)
        {
            // update working projects (add)
            if (trust.UserID == Core.UserID)
            {
                OpStorage local = GetStorage(Core.UserID);

                foreach (uint project in Trust.LocalTrust.Links.Keys)
                    if (!Working.ContainsKey(project))
                    {
                        if(local != null)
                            LoadHeaderFile(GetWorkingPath(project), local, false, true);

                        Working[project] = new WorkingStorage(this, project);
                    }
            }

            // remove all higher changes, reload with new highers (cause link changed
            foreach (WorkingStorage working in Working.Values )
                if (Core.UserID == trust.UserID || Trust.IsHigher(trust.UserID, working.ProjectID))
                {
                    working.RemoveAllHigherChanges();

                    foreach (ulong uplink in Trust.GetAutoInheritIDs(Core.UserID, working.ProjectID))
                        working.RefreshHigherChanges(uplink);
                }
        }