Advertisement
Guest User

Replacer.cs

a guest
May 16th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using Microsoft.VisualBasic.FileIO;
  2. using System.IO;
  3.  
  4. namespace ReplaceIcon
  5. {
  6.     public class Replacer
  7.     {
  8.         public void Replace(ThemeIcon current, ThemeIcon replacement)
  9.         {
  10.             foreach (var size in current.Sizes)
  11.             {
  12.                 Recycle(current[size]); // move an icon to recycle bin (trash)
  13.  
  14.                 foreach (var related in size.Related)
  15.                 {
  16.                     if (File.Exists(replacement[related]))
  17.                     {
  18.                         // TODO: if it's a symbol link make sure it will replace an icon, not the symbol link
  19.                         Copy(replacement[related], current[size]);
  20.  
  21.                         break;
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.  
  27.         public void Copy(string source, string destination)
  28.         {
  29.             if (File.Exists(source))
  30.                 File.Copy(source, destination);
  31.         }
  32.  
  33.         public void Recycle(string icon)
  34.         {
  35.             if (File.Exists(icon))
  36.                 FileSystem.DeleteFile(icon, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement