Changeset 1862


Ignore:
Timestamp:
3/1/2010 5:50:12 AM (4 years ago)
Author:
lowjoel
Message:

Forward-port from Eraser 6.0: Generate names which are valid, not any of those reserved file names (e.g. con, prn, nul)

Location:
trunk/eraser6
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6

  • trunk/eraser6/Eraser.Manager/FileSystem.cs

    r1802 r1862  
    2323using System.Collections.Generic; 
    2424using System.Text; 
     25using System.IO; 
    2526using Eraser.Util; 
    26 using System.IO; 
    2727 
    2828namespace Eraser.Manager 
     
    4343        public static string GenerateRandomFileName(DirectoryInfo info, int length) 
    4444        { 
    45             //Get a random file name 
     45            //Get the PRNG we are going to use 
    4646            Prng prng = ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng]; 
     47 
     48            //Initialsie the base name, if any. 
    4749            string resultPrefix = info == null ? string.Empty : info.FullName + 
    4850                Path.DirectorySeparatorChar; 
     51 
     52            //Variables to store the intermediates. 
    4953            byte[] resultAry = new byte[length]; 
    5054            string result = string.Empty; 
     55            List<string> prohibitedFileNames = new List<string>(new string[] { 
     56                "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", 
     57                "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", 
     58                "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" 
     59            }); 
    5160 
    5261            do 
     
    6372                result = Encoding.UTF8.GetString(resultAry); 
    6473            } 
    65             while (info != null && (Directory.Exists(resultPrefix + result) || 
    66                 File.Exists(resultPrefix + result))); 
     74            while (info != null && 
     75                prohibitedFileNames.IndexOf(Path.GetFileNameWithoutExtension(result)) != -1 || 
     76                (Directory.Exists(resultPrefix + result) || File.Exists(resultPrefix + result))); 
    6777            return resultPrefix + result; 
    6878        } 
  • trunk/eraser6/Eraser.msbuild

  • trunk/eraser6/Eraser/BlackBoxMainForm.it.resx

  • trunk/eraser6/Eraser/BlackBoxUploadForm.it.resx

Note: See TracChangeset for help on using the changeset viewer.