示例#1
0
        public void OnExit(object sender, ExitEventArgs args)
        {
            new Thread(() => {
                XDocument doc  = new XDocument();
                XElement root  = new XElement("UserData");
                XElement xElem = new XElement(
                    "bookmarks",
                    bookmarks.Select(x => {
                    if (x.Key == "")
                    {
                        return(null);
                    }
                    return(new XElement("bookmarks",
                                        new XAttribute("k", x.Key),
                                        new XAttribute("v", x.Value.lastChapter),
                                        new XAttribute("d", x.Value.lastRead.ToString())));
                })
                    );
                root.Add(xElem);
                doc.Add(root);

                using (StreamWriter s = new StreamWriter(File.Create(USER_DATA_FILE))) {
                    s.Write(Meow.ToMeow(doc.ToString(SaveOptions.DisableFormatting)));
                    s.Close();
                }
            }).Start();
        }
示例#2
0
        public void AsyncInit()
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = false;
            worker.DoWork += (sender, e) => {
                api.FetchIndex(true); //Fetches the mainIndex from a file or the internet if the cached file is too old
                try {                 //Try to load the user configs and bookmarks
                    using (StreamReader f = new StreamReader(File.OpenRead(USER_DATA_FILE))) {
                        XDocument doc = XDocument.Parse(Meow.FromMeow(f.ReadToEnd()));
                        bookmarks = doc.Descendants("UserData").Descendants("bookmarks").ToDictionary(x => {
                            if (x.Attribute("k") == null)
                            {
                                return("");
                            }
                            return((string)x.Attribute("k"));
                        }, x => {
                            if (x.Attribute("k") == null)
                            {
                                return(null);
                            }
                            return(new MangaBookmark()
                            {
                                lastChapter = (int)x.Attribute("v"), id = (string)x.Attribute("k"), lastRead = DateTime.Parse((string)x.Attribute("d"))
                            });
                        });
                    }
                }//Any goes wrong, just reset all bookmarks
                catch (Exception) { bookmarks = new Dictionary <string, MangaBookmark>(); }
            };
            worker.RunWorkerCompleted += (sender, e) => {
                SearchPane.Visibility = DisplayPane.Visibility = Visibility.Visible; ProgressTip = "Idle";
                AsyncFetchUpdates();
                AsyncFetchRecents();
            };
            worker.RunWorkerAsync();
        }