Exemplo n.º 1
0
        /// <summary>
        /// 对比文件
        /// </summary>
        /// <param name="localBookmarks"></param>
        public static bool ContrastBookmarks(List <MyBookmarks> localBookmarks)
        {
            if (localBookmarks == null)
            {
                return(false);
            }
            string datajsPath = System.Environment.CurrentDirectory + @"\old_data.js";
            string datajs     = StringConvert.FileRead(datajsPath);

            datajs = datajs.Substring((datajs.IndexOf("=") + 1));
            BookmarksType bookmarksType = (BookmarksType)StringConvert.JsonToList <BookmarksType>(datajs);
            //List<MyBookmarks> onlineBookmarks = bookmarksType.Info;
            bool rel = false;

            foreach (MyBookmarks item in localBookmarks)
            {
                if (!bookmarksType.Info.Any(a => a.Url == item.Url))
                {
                    bookmarksType.Info.Add(item);
                    rel = true;
                }
            }
            if (rel)
            {
                SaveDataJs(localBookmarks);
            }
            return(rel);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 保存配置文件
 /// </summary>
 public static bool SaveConfigData()
 {
     if (ConfigDataService.ConfigData != null)
     {
         //string path = System.Environment.CurrentDirectory + @"\config.json";
         StringConvert.FileWrite(FilePath, StringConvert.ListToJson(ConfigDataService.ConfigData));
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取Chrome浏览器书签对象
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public ChromeBookmarks GetChromeBookmarksData(string filePath)
        {
            string str             = StringConvert.FileRead(filePath);
            object chromeBookmarks = StringConvert.JsonToList <ChromeBookmarks>(str);

            if (chromeBookmarks != null)
            {
                return((ChromeBookmarks)chromeBookmarks);
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 将文件保存成data.js文件
        /// </summary>
        /// <param name="localBookmarks">本地书签文件数据</param>
        public static void SaveDataJs(List <MyBookmarks> localBookmarks)
        {
            string dataPath   = System.Environment.CurrentDirectory + @"\data.json";
            string datajsPath = System.Environment.CurrentDirectory + @"\data.js";

            if (BookmarksData.SaveMyBookmarksToJsonFile(localBookmarks, dataPath))
            {
                string cont = "var InfoData =" + StringConvert.FileRead(dataPath);
                StringConvert.FileWrite(datajsPath, cont);
            }
        }
Exemplo n.º 5
0
 public static void LoadConfig()
 {
     //string path = System.Environment.CurrentDirectory + @"\config.json";
     if (File.Exists(FilePath))
     {
         _configData = (ConfigModel)StringConvert.JsonToList <ConfigModel>(StringConvert.FileRead(FilePath));
     }
     else
     {
         _configData = new ConfigModel();
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 保存成json文件
        /// </summary>
        /// <param name="myBookmarkses"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static bool SaveMyBookmarksToJsonFile(List <MyBookmarks> myBookmarkses, string filePath)
        {
            BookmarksType bookmarksType = new BookmarksType();

            bookmarksType.Info = myBookmarkses;
            List <string> types = new List <string>();

            foreach (var item in myBookmarkses.GroupBy(a => a.Type).ToList())
            {
                types.Add(item.Key);
            }
            bookmarksType.Type = types;
            return(StringConvert.FileWrite(filePath, StringConvert.ListToJson(bookmarksType)));
        }