コード例 #1
0
        public static void CreateKeyfile(string filePath)
        {
            NullChecks.Strings(filePath);
            const string keyfileExtension = ".key";

            // Generate a random name if the path is a directory
            if (Directory.Exists(filePath))
            {
                string randomFileName = AnonymousRename.GenerateRandomFileName() + keyfileExtension;
                filePath = Path.Combine(filePath, randomFileName);
            }
            if (!File.Exists(filePath))
            {
                // Append .key extension if missing
                if (!filePath.EndsWith(keyfileExtension, StringComparison.InvariantCulture))
                {
                    filePath += keyfileExtension;
                }
                Keyfiles.GenerateKeyfile(filePath);
            }
            else
            {
                Console.WriteLine("Error: A file with this name already exists.");
            }
        }
コード例 #2
0
 public static void RestoreDirectoryName(string folderPath)
 {
     try
     {
         NullChecks.Strings(folderPath);
         string anonymisedDirectoryName = Path.GetFileName(folderPath);
         // Get the path where the original directory name is stored
         string storageFileName = $"{anonymisedDirectoryName}.txt";
         string storageFilePath = Path.Combine(folderPath, storageFileName);
         if (File.Exists(storageFilePath))
         {
             string originalDirectoryName = File.ReadAllText(storageFilePath);
             string originalDirectoryPath = folderPath.Replace(anonymisedDirectoryName, originalDirectoryName);
             Directory.Move(folderPath, originalDirectoryPath);
             storageFilePath = Path.Combine(originalDirectoryPath, storageFileName);
             if (File.Exists(storageFilePath))
             {
                 File.Delete(storageFilePath);
             }
         }
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.Error(folderPath, ex.GetType().Name, "Unable to restore original directory name.");
     }
 }
コード例 #3
0
 public static string GetAnonymousFileName(string filePath)
 {
     try
     {
         NullChecks.Strings(filePath);
         string originalFileName  = Path.GetFileName(filePath);
         string randomFileName    = GenerateRandomFileName();
         string anonymousFilePath = filePath.Replace(originalFileName, randomFileName);
         return(anonymousFilePath);
     }
     catch (ArgumentException ex)
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Bug);
         DisplayMessage.Error(filePath, ex.GetType().Name, "Unable to get anonymous file name. This is a bug - please report it.");
         return(filePath);
     }
 }