示例#1
0
        public static void LoadSettings()
        {
            if (!File.Exists("settings.xml"))
            {
                return;
            }
            var findex = new FileIndex()
            {
                FileName = "settings.xml", RootPath = Application.StartupPath
            };

            using (FileStream fs = new FileStream("settings.xml", FileMode.Open, FileAccess.Read))
            {
                findex.Load(fs, new DirectoryInfoWrapper(new DirectoryInfo(Application.StartupPath)), "settings.xml");
            }

            FileIndexes.Add(findex);

            var s  = XDocument.Load("settings.xml");
            var fr = s.Descendants("settings").First();

            Stuff.PasswordHash = fr.Attribute("password").Value;
            foreach (var descendant in s.Descendants("path"))
            {
                RecentPathes.Add(descendant.Value);
            }

            List <DirectoryEntry> direntries  = new List <DirectoryEntry>();
            List <FileEntry>      fileentries = new List <FileEntry>();

            //#region load directory and files entries
            //var entries = s.Descendants("entries").First();
            //foreach (var item in entries.Descendants("directory"))
            //{
            //    var id = int.Parse(item.Attribute("id").Value);
            //    var path = item.Value;
            //    //var dir = new DirectoryInfo(path);
            //    //path = dir.Parent.GetDirectories(dir.Name).First().FullName;
            //    direntries.Add(new DirectoryEntry() { Id = id, Path = path });
            //}
            //foreach (var item in entries.Descendants("file"))
            //{
            //    var id = int.Parse(item.Attribute("id").Value);
            //    var dirId = int.Parse(item.Attribute("dirId").Value);
            //    var name = item.Value;

            //    var dir = direntries.First(z => z.Id == dirId);
            //    //var path = Path.Combine(dir.Path, name);
            //    //var diri = new DirectoryInfo(dir.Path);
            //    //name = diri.GetFiles(name).First().Name;

            //    fileentries.Add(new FileEntry() { Id = id, Directory = dir, Name = name });
            //}
            //#endregion


            //#region meta

            //var metas = s.Descendants("meta").FirstOrDefault();
            //if (metas != null)
            //{
            //    foreach (var item in metas.Descendants("file"))
            //    {
            //        var fid = int.Parse(item.Attribute("fileId").Value);
            //        var f = fileentries.First(z => z.Id == fid);
            //        Stuff.MetaInfos.Add(new FileMetaInfo() { File = new FileInfoWrapper(new FileInfo(f.FullName)) });
            //        var minf = Stuff.MetaInfos.Last();

            //        foreach (var kitem in item.Descendants())
            //        {
            //            if (kitem.Name == "keywordsMetaInfo")
            //            {
            //                minf.Infos.Add(new KeywordsMetaInfo() { Parent = minf, Keywords = kitem.Value });
            //            }

            //        }

            //    }
            //}
            //#endregion
            foreach (var descendant in s.Descendants("tab"))
            {
                var hint   = descendant.Attribute("hint").Value;
                var owner  = descendant.Attribute("owner").Value;
                var path   = descendant.Attribute("path").Value;
                var filter = descendant.Attribute("filter").Value;

                var tab = new TabInfo()
                {
                    Filter = filter, Path = path, Hint = hint
                };
                tab.Owner = owner;
                Stuff.AddTab(tab);
            }

            foreach (var descendant in s.Descendants("library"))
            {
                var name = descendant.Attribute("name").Value;
                var path = descendant.Attribute("path").Value;
                Stuff.Libraries.Add(new FilesystemLibrary()
                {
                    Name = name, BaseDirectory = new DirectoryInfoWrapper(path)
                });
            }

            foreach (var descendant in s.Descendants("hotkey"))
            {
                var path    = descendant.Attribute("path").Value;
                var enabled = bool.Parse(descendant.Attribute("enabled").Value);
                var key     = (Keys)Enum.Parse(typeof(Keys), descendant.Attribute("key").Value);
                Stuff.Hotkeys.Add(new HotkeyShortcutInfo()
                {
                    IsEnabled = enabled, Hotkey = key, Path = path
                });
            }

            foreach (var descendant in s.Descendants("shortcut"))
            {
                var name = descendant.Attribute("name").Value;

                if (descendant.Attribute("type") != null)
                {
                    var tp = descendant.Attribute("type").Value;
                    switch (tp)
                    {
                    case "url":
                        var url = descendant.Element("url").Value;
                        Stuff.Shortcuts.Add(new UrlShortcutInfo(name, url));
                        break;

                    case "cmd":
                        var    wd   = descendant.Attribute("workdir").Value;
                        string args = null;
                        if (descendant.Element("args") != null)
                        {
                            args = descendant.Element("args").Value;
                        }

                        string appName = null;
                        if (descendant.Element("app") != null)
                        {
                            appName = descendant.Element("app").Value;
                        }
                        Stuff.Shortcuts.Add(new CmdShortcutInfo(name, args, wd, appName));
                        break;
                    }
                }
                else
                {
                    var path = descendant.Attribute("path").Value;
                    Stuff.Shortcuts.Add(new AppShortcutInfo(path, name));
                }
            }

            //foreach (var descendant in s.Descendants("tag"))
            //{
            //    var name = descendant.Attribute("name").Value;

            //    string flags = "";
            //    if (descendant.Attribute("flags") != null) { flags = descendant.Attribute("flags").Value; }

            //    var tag = new TagInfo() { Name = name, IsHidden = flags.Contains("hidden") };

            //    var snms = descendant.Descendants("synonym");
            //    foreach (var item in snms)
            //    {
            //        tag.Synonyms.Add(item.Value.Trim());
            //    }

            //    Stuff.Tags.Add(tag);
            //    foreach (var item in descendant.Descendants("file"))
            //    {
            //        var arr1 = item.Attribute("id").Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
            //        foreach (var aitem in arr1)
            //        {
            //            var ff = fileentries.First(z => z.Id == aitem);
            //            tag.AddFile(new FileInfoWrapper(ff.FullName));
            //        }
            //    }
            //}

            foreach (var descendant in s.Descendants("fileContextMenuItem"))
            {
                var    title   = descendant.Attribute("title").Value;
                var    appName = descendant.Attribute("appName").Value;
                string args    = null;
                if (descendant.Element("arguments") != null)
                {
                    args = descendant.Element("arguments").Value;
                }
                var f = new FileContextMenuItem()
                {
                    Title = title, AppName = appName, Arguments = args
                };
                Stuff.FileContextMenuItems.Add(f);
            }
            foreach (var descendant in s.Descendants("site"))
            {
                var path = descendant.Value;
                var f    = new OfflineSiteInfo()
                {
                    Path = path
                };
                Stuff.OfflineSites.Add(f);
            }
            var root = s.Descendants("bookmarks").First();

            LoadBookmarks(root);
        }
示例#2
0
 public static void AddFileIndex(FileIndex findex)
 {
     FileIndexes.Add(findex);
 }