Exemplo n.º 1
0
 /// <summary>
 /// Gets the type with the given name. If it does not exit the user is asked if it should be created.
 /// </summary>
 /// <param name="typeName">The name of the franchise type to get or create</param>
 /// <param name="wallpaperFranchiseType">The found or created franchise type</param>
 /// <returns>If a new franchise type was created.</returns>
 private void GetOrCreateType(string typeName, bool ignoreMissing, out WallpaperType wallpaperFranchiseType)
 {
     if (ignoreMissing)
     {
         wallpaperFranchiseType = WallpaperType.GetOrCreate(typeName);
     }
     else
     {
         if (WallpaperType.TryGet(typeName, out WallpaperType? foundType)) //Check if type is unknown
         {
             wallpaperFranchiseType = foundType;
         }
         else
         {
             Console.Write($"The wallpaper type with the name '{typeName}' does not exist. Do you want to create it?");
             if (UserInterface.GetUserInput())
             {
                 wallpaperFranchiseType = new WallpaperType(typeName);
             }
             else
             {
                 Console.WriteLine();
                 throw new WallpaperBuildExeption("Franchise Type not found and not created.", true);
             }
             Console.WriteLine();
         }
     }
 }
Exemplo n.º 2
0
        public static Tuple <int, int> Merge()
        {
            int countDeleted = 0;
            int countCopied  = 0;

            if (false) //Environment.OSVersion.Platform == PlatformID.Win32NT
            {
                throw new NotImplementedException();
                //Implement faster method of coping files here
            }
            else
            {
                //Delete all old files
                foreach (var currentFile in MergedWallpaperDirectory.GetFiles())
                {
                    if (WallpaperFileHelper.IsImage(currentFile))
                    {
                        currentFile.Delete();
                        countDeleted++;
                    }
                }

                //Get excluded types
                WallpaperType excludedType;
                if (WallpaperType.TryGet("X-MAS", out WallpaperType? type))
                {
                    excludedType = type;
                }
                else
                {
                    throw new ArgumentNullException("Franchise not found.", nameof(excludedType));
                }

                //Copy all wallpapers that are not excluded
                foreach (var currentWallpaper in Wallpapers)
                {
                    if (currentWallpaper.Franchise.Type != excludedType)
                    {
                        currentWallpaper.File.CopyTo(Path.Combine(MergedWallpaperDirectory.FullName, currentWallpaper.File.Name));
                        countCopied++;
                    }
                }
            }

            return(new Tuple <int, int>(countDeleted, countCopied));
        }