Esempio n. 1
0
        private void SetBookmarksFromConfig()
        {
            int    i = 0;
            string bookmark;

            do
            {
                bookmark = m_config.GetValue($"bookmark{i}");
                if (bookmark != null)
                {
                    string[] bookmarkData = bookmark.Split('|');

                    if (bookmarkData.Length == 4)
                    {
                        BookmarkContainer container   = (bookmarkData[0] == "Tree") ? BookmarkContainer.TreeView : BookmarkContainer.Toolbar;
                        BookmarkType      type        = (bookmarkData[1] == "File") ? BookmarkType.File : BookmarkType.Directory;
                        string            displayName = bookmarkData[2];
                        string            path        = bookmarkData[3];

                        AddBookmark(path, displayName, type, container);
                    }
                }

                i++;
            } while (bookmark != null);
        }
        public bool LoadFromFile(string filename, string password)
        {
            try
            {
                LoadedFromFile = true;

                var settings          = new StorageManagerSettings(false, Environment.ProcessorCount, true, password);
                var storageManager    = new StorageManager(settings);
                var bookmarkContainer = storageManager.DeserializeObjectFromFile <BookmarkContainer>(filename, null);

                if (bookmarkContainer?.RootFolder == null || string.IsNullOrEmpty(bookmarkContainer.ContainerId))
                {
                    return(false);
                }

                int changesMade = PrepareContainer(bookmarkContainer);
                _bookmarkContainer = bookmarkContainer;
                RootFolder         = _bookmarkContainer.RootFolder;
                if (changesMade > 0)
                {
                    Log.Information("Loaded Bookmaeksfile which had {changesMade} number of issues like faulty links. Resaving fixed file", changesMade);
                    SaveToFile(filename, password);
                }

                IsModified = true;

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "BookmarkManager.LoadFromFile(string filename, string password) : " + ex.Message, ex);
            }

            return(false);
        }
Esempio n. 3
0
        protected void FillDbTestData()
        {
            ApplicationUser testUser = new ApplicationUser {
                Id       = this.TestUserId,
                UserName = "******"
            };

            _db.Users.Add(testUser);
            _db.SaveChanges();

            BookmarkContainer testContainer = new BookmarkContainer(testUser.Id, "Test Container",
                                                                    0);

            _db.BookmarkContainers.Add(testContainer);
            _db.SaveChanges();
            this.TestBookmarkContainer = testContainer;

            BookmarkGroup testGroup = new BookmarkGroup("Test Group", "#000000", 0,
                                                        testContainer.BookmarkContainerId);

            _db.BookmarkGroups.Add(testGroup);
            _db.SaveChanges();
            this.TestBookmarkGroup = testGroup;

            Bookmark testBookmark = new Bookmark("Test Bookmark", "http://example.com",
                                                 "Test Notes", 0, testGroup.BookmarkGroupId);

            _db.Bookmarks.Add(testBookmark);
            _db.SaveChanges();
            this.TestBookmark = testBookmark;
        }
        private int PrepareContainer(BookmarkContainer bookmarkContainer)
        {
            int changes    = 0;
            var rootFolder = bookmarkContainer.RootFolder;

            rootFolder.SortOrder = 0;

            if (string.IsNullOrEmpty(bookmarkContainer.ContainerId))
            {
                bookmarkContainer.ContainerId = Guid.NewGuid().ToString();
                changes++;
            }

            if (string.IsNullOrEmpty(rootFolder.Id))
            {
                rootFolder.Id = Guid.NewGuid().ToString();
                changes++;
            }

            if (rootFolder.BookmarkFolders == null)
            {
                rootFolder.BookmarkFolders = new List <BookmarkFolder>();
            }

            return(RecursiveValidationOnContainer(rootFolder, null) + changes);
        }
Esempio n. 5
0
    internal void OnPreviousBookmark()
    {
        BookmarkContainer bookmark = bookmarkContainers.LastOrDefault(x => x.data._time < atsc.CurrentBeat);

        if (bookmark != null)
        {
            atsc.MoveToTimeInBeats(bookmark.data._time);
        }
    }
Esempio n. 6
0
    internal void OnNextBookmark()
    {
        BookmarkContainer bookmark = bookmarkContainers.Find(x => x.data._time > atsc.CurrentBeat);

        if (bookmark != null)
        {
            atsc.MoveToTimeInBeats(bookmark.data._time);
        }
    }
    public void OnPreviousBookmark(InputAction.CallbackContext context)
    {
        if (!context.performed)
        {
            return;
        }
        BookmarkContainer bookmark = bookmarkContainers.FirstOrDefault(x => x.data._time < atsc.CurrentBeat);

        if (bookmark != null)
        {
            atsc.MoveToTimeInBeats(bookmark.data._time);
        }
    }
Esempio n. 8
0
    public void JumpToNextBookmark()
    {
        BookmarkContainer targetBookmark = bookmarkContainers.FindAll(f => f.data._time > atsc.CurrentBeat).OrderBy(o => o.data._time).FirstOrDefault();

        if (targetBookmark != null)
        {
            atsc.MoveToTimeInBeats(targetBookmark.data._time);
        }
        else
        {
            Debug.Log("No future bookmarks found");
        }
    }
Esempio n. 9
0
    private IEnumerator Start()
    {
        yield return(new WaitForSeconds(0.1f)); //Wait for time

        bookmarkContainers = BeatSaberSongContainer.Instance.map._bookmarks.Select(bookmark =>
        {
            BookmarkContainer container = Instantiate(bookmarkContainerPrefab, transform).GetComponent <BookmarkContainer>();
            container.name = bookmark._name;
            container.Init(this, bookmark);
            container.RefreshPosition(timelineCanvas.sizeDelta.x + CANVAS_WIDTH_OFFSET);
            return(container);
        }).OrderBy(it => it.data._time).ToList();
    }
Esempio n. 10
0
    public void JumpToPreviousBookmark()
    {
        BookmarkContainer targetBookmark = bookmarkContainers.FindAll(f => f.data._time < atsc.CurrentBeat).OrderByDescending(o => o.data._time).FirstOrDefault();

        if (targetBookmark != null)
        {
            atsc.MoveToTimeInBeats(targetBookmark.data._time);
        }
        else
        {
            Debug.Log("No past bookmarks found");
        }
    }
Esempio n. 11
0
        private void AddBookmark(string path, string displayName, BookmarkType type, BookmarkContainer container)
        {
            int         imageIndex = 0;
            BookmarkTag tag        = null;

            if (type == BookmarkType.Directory)
            {
                imageIndex = m_iconListManager.AddFolderIcon(path, true);
                tag        = new BookmarkDirectoryTag(path);
            }
            else
            {
                imageIndex = m_iconListManager.AddFileIcon(path, true);
                tag        = new BookmarkFileTag(path);
            }

            if (tag != null)
            {
                tag.DisplayName = displayName;

                if (container == BookmarkContainer.Toolbar)
                {
                    var item = new ToolStripButtonWithContextMenu()
                    {
                        Text              = displayName,
                        Image             = m_smallImageList.Images[imageIndex],
                        TextImageRelation = TextImageRelation.ImageAboveText,
                        Tag = tag,
                        ContextMenuStrip = BookmarksContextMenuStrip,
                        Font             = BackToolStripButton.Font,
                        ToolTipText      = (tag as BookmarkTag).Path
                    };

                    item.Click += Bookmark_Click;

                    NavigationToolStrip.Items.Add(item);
                }
                else if (container == BookmarkContainer.TreeView)
                {
                    TreeNode item = new TreeNode(displayName);
                    item.ImageIndex  = item.SelectedImageIndex = imageIndex;
                    item.Tag         = tag;
                    item.ToolTipText = (tag as BookmarkTag).Path;

                    DrivesTreeView.Nodes[0].Nodes.Add(item);
                }
            }
        }
Esempio n. 12
0
        public async Task <BookmarkContainer?> UpdateBookmarkContainer(string userId,
                                                                       BookmarkContainer bookmarkContainer)
        {
            BookmarkContainer?existingBookmarkContainer = await this.db.BookmarkContainers
                                                          .SingleOrDefaultAsync(bc =>
                                                                                bc.BookmarkContainerId == bookmarkContainer.BookmarkContainerId);

            if (existingBookmarkContainer == null ||
                !BookmarkOwnershipTools
                .IsBookmarkContainerOwner(this.db, userId, bookmarkContainer.BookmarkContainerId))
            {
                return(null);
            }

            // If the sort order has changed, then the other containers need to be shuffled around
            if (existingBookmarkContainer.SortOrder < bookmarkContainer.SortOrder)
            {
                // The container has been moved to a higher sort order
                var affectedContainers = db.BookmarkContainers
                                         .Where(bc => bc.ApplicationUserId == userId)
                                         .Where(bc => bc.SortOrder > existingBookmarkContainer.SortOrder)
                                         .Where(bc => bc.SortOrder <= bookmarkContainer.SortOrder)
                                         .ToList();

                affectedContainers.ForEach(bc => bc.SortOrder -= 1);
                // Let the save changes below save this
            }
            else if (existingBookmarkContainer.SortOrder > bookmarkContainer.SortOrder)
            {
                // The container has been moved to a lower sort order
                var affectedContainers = db.BookmarkContainers
                                         .Where(bc => bc.ApplicationUserId == userId)
                                         .Where(bc => bc.SortOrder < existingBookmarkContainer.SortOrder)
                                         .Where(bc => bc.SortOrder >= bookmarkContainer.SortOrder)
                                         .ToList();

                affectedContainers.ForEach(bc => bc.SortOrder += 1);
                // Let the save changes below save this
            }

            this.db.Entry(bookmarkContainer).State = EntityState.Modified;
            await this.db.SaveChangesAsync();

            return(bookmarkContainer);
        }
Esempio n. 13
0
        private void BookmarkContainer_DragDrop(object sender, DragEventArgs e)
        {
            List <string>     pathsToAdd    = new List <string>();
            BookmarkContainer containerType = (sender == NavigationToolStrip) ? BookmarkContainer.Toolbar : BookmarkContainer.TreeView;

            if (e.Data.GetDataPresent(typeof(ListView.SelectedListViewItemCollection)))
            {
                foreach (ListViewItem current in (ListView.SelectedListViewItemCollection)e.Data.GetData(typeof(ListView.SelectedListViewItemCollection)))
                {
                    if (current.Tag is PathTag)
                    {
                        pathsToAdd.Add((current.Tag as PathTag).Path);
                        break;  // Only add first
                    }
                }
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                foreach (var file in (string[])e.Data.GetData(DataFormats.FileDrop))
                {
                    pathsToAdd.Add(file);
                    break;  // Only add first
                }
            }

            foreach (string path in pathsToAdd)
            {
                if (Directory.Exists(path))
                {
                    AddBookmark(path, Path.GetFileName(path), BookmarkType.Directory, containerType);
                    break;  // Only add first
                }
                else if (File.Exists(path))
                {
                    AddBookmark(path, Path.GetFileName(path), BookmarkType.File, containerType);
                    break;  // Only add first
                }
            }
        }
Esempio n. 14
0
        public bool LoadFromFileAndAppendBookmarks(string filename, string password)
        {
            try
            {
                LoadedFromFile = true;

                var settings          = new StorageManagerSettings(false, Environment.ProcessorCount, true, password);
                var storageManager    = new StorageManager(settings);
                var bookmarkContainer = storageManager.DeserializeObjectFromFile <BookmarkContainer>(filename, null);

                //storageManager.DeserializeObjectFromFile throws exception if the password is Incorrect and deserialization fails
                //just in case bookmarkContainer is null
                if (bookmarkContainer?.RootFolder == null || string.IsNullOrEmpty(bookmarkContainer.ContainerId))
                {
                    throw new Exception("LoadFromFileAndAppendBookmarks failed, bookmarkContainer was null");
                }

                PrepareContainer(bookmarkContainer);

                if (_bookmarkContainer == null)
                {
                    _bookmarkContainer = bookmarkContainer;
                }
                else
                {
                    RecursiveAdd(_bookmarkContainer.RootFolder, bookmarkContainer.RootFolder);
                }

                RootFolder = _bookmarkContainer.RootFolder;
                IsModified = true;
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "BookmarkManager.LoadFromFile(string filename, string password) : " + ex.Message);
            }

            return(false);
        }
Esempio n. 15
0
 public static BookmarkContainerDto MapToDto(this BookmarkContainer bookmarkContainer)
 {
     return(new BookmarkContainerDto(bookmarkContainer.BookmarkContainerId,
                                     bookmarkContainer.Title, bookmarkContainer.SortOrder,
                                     bookmarkContainer.BookmarkGroups?.Select(bg => bg.MapToDto()).ToList()));
 }
Esempio n. 16
0
 internal void DeleteBookmark(BookmarkContainer container)
 {
     bookmarkContainers.Remove(container);
     BeatSaberSongContainer.Instance.map._bookmarks = bookmarkContainers.Select(x => x.data).ToList();
     OnBookmarksUpdated.Invoke();
 }
Esempio n. 17
0
 public void ClearBookmarks()
 {
     _bookmarkContainer = CreateBookmarkContainer();
     IsModified         = true;
 }
Esempio n. 18
0
 public BookmarkManager()
 {
     _bookmarkContainer = CreateBookmarkContainer();
     RootFolder         = _bookmarkContainer.RootFolder;
 }