Exemplo n.º 1
0
 private static void CreateShortcut(FavoriteItem item, string saveLocation)
 {
     try
     {
         using (var writer = new StreamWriter(saveLocation))
         {
             writer.WriteLine("[InternetShortcut]");
             writer.WriteLine($"URL={item.URL}");
             writer.Flush();
         }
     }
     catch (Exception e)
     {
         WriteLine($"Error while saving {item.Title}, '{item.URL}' to location: {saveLocation}\nThe error message was:\n{e.Message}");
     }
 }
Exemplo n.º 2
0
        private static void Save(FavoriteItem item, IEnumerable <FavoriteItem> items)
        {
            WriteLine($"Saving item '{item.Title}'");

            var dir = FolderLineage(items, item)
                      .Reverse()
                      .Aggregate(TargetRoot, (acc, x) => Q(acc, x.Title.Contains("Favorites_Bar") ? x.Title.Replace("_", " ").Trim():x.Title), x => x);

            WriteLine($"Deduced '{dir}' as directory...");

            if (!Directory.Exists(dir))
            {
                WriteLine($"Creating directory: '{dir}'");
                Directory.CreateDirectory(dir);
            }

            CreateShortcut(item, Path.Combine(dir, $"{Path.GetInvalidPathChars().Aggregate(item.Title, (title, x) => title.Replace(x, '_'), x => x)}.url"));
        }
Exemplo n.º 3
0
        private static IEnumerable <FavoriteItem> FolderLineage(IEnumerable <FavoriteItem> source, FavoriteItem target)
        {
            target = source.FirstOrDefault(x => x.ParentId == target.ParentId && x.IsFolder);
            while (target != null && !string.IsNullOrWhiteSpace(target.ParentId))
            {
                yield return(target);

                target = source.FirstOrDefault(x => x.ItemId == target.ParentId && x.IsFolder);
            }
        }