- public struct OneFile
- {
- public String size;
- public String lastDate;
- }
-
- ///<summary>This class is used for hard drive methods</summary>
- ///<remarks>
- ///Contains method for hard drive snapshot, comparing hard drive snapshot and incrementing the number of scaned files
- ///</remarks>
- class DriveAccess
- {
- /// <summary>
- /// StringCollection containing the scaned folder paths
- /// </summary>
- //private static String[,] _allFiles;
- Dictionary<String, OneFile> _allFiles;
-
- public Dictionary<String, OneFile> allFiles
- {
- get { return _allFiles; }
- set { _allFiles = value; }
- }
-
- /// <summary>
- /// Construct, instanciates the StringCollection
- /// </summary>
- public DriveAccess()
- {
- //allFiles = new String[50000,3];
- _allFiles = new Dictionary<String, OneFile>();
- }
-
- /// <summary>
- /// Methods which gets all files and folders in a directory. It uses a Stack which is the best way to
- /// deal with non recursive algorithm for scan.
- /// </summary>
- /// <param name="inDirectory">The directory we want to scan</param>
- public void GetAllFiles(String inDirectory)
- {
- // Define new stack
- Stack<String> myStack = new Stack<String>();
-
- // Get all subdirectories in inDirectory
- String[] files = Directory.GetFileSystemEntries(inDirectory);
-
- // Define String containing the poped value from stack
- String poped;
-
- // We push all subdirectories in the stack
- foreach (String fileName in files)
- {
- myStack.Push(fileName);
- }
-
- int i = 0;
-
- // Let's do the main loop
- while (myStack.Count > 0)
- {
- // Pop a value
- poped = myStack.Pop();
-
- // If it is a directory
- if (Directory.Exists(poped))
- {
- try
- {
- // Get it's subdirectories
- files = Directory.GetFileSystemEntries(poped);
-
- // Push these subdirectories
- foreach (String fileName in files)
- {
- myStack.Push(fileName);
- }
- }
- catch
- { }
- }
- // We got a file
- else
- {
- // Get informations about the file
- FileInfo myFileInfo = new FileInfo(poped);
-
- // Add it to the StringCollection attribute
- //allFiles[i, 0] = poped;
- //allFiles[i, 1] = myFileInfo.Length.ToString();
- //allFiles[i, 2] = myFileInfo.LastWriteTime.ToString();
- //i++;
- OneFile myOneFile;
- myOneFile.size = myFileInfo.Length.ToString();
- myOneFile.lastDate = myFileInfo.LastWriteTime.ToString();
-
- _allFiles[poped] = myOneFile;
-
- // Number of scaned files and directories ++
- incNum();
- }
- }
- }
-
-
-
- /// <summary>
- /// Compares two StringCollections and returns the differences between these StringCollections
- /// </summary>
- /// <param name="inStringCollec">One of the StringCollection we want to compare</param>
- /// <returns>Differences between the two StringCollections</returns>
- public Dictionary<String, OneFile> compare(Dictionary<String, OneFile> inStringCollec)
- {
- // Define the StringCollection we will return
- Dictionary<String, OneFile> returnCollection = new Dictionary<String, OneFile>();
- OneFile myTempOneFile;
-
- // Foreach String into one of the String[,]
- foreach(KeyValuePair<String, OneFile> myPair in _allFiles)
- {
- if (inStringCollec.ContainsKey(myPair.Key))
- {
- if (inStringCollec[myPair.Key].lastDate != myPair.Value.lastDate)
- {
- myTempOneFile.lastDate = "<span style=\"color:red;\">" + _allFiles[myPair.Key].lastDate + "</span>";
- myTempOneFile.size = _allFiles[myPair.Key].size;
- returnCollection[myPair.Key] = myTempOneFile;
- }
-
- if (inStringCollec[myPair.Key].size != myPair.Value.size)
- {
- myTempOneFile.lastDate = _allFiles[myPair.Key].lastDate;
- myTempOneFile.size = "<span style=\"color:red;\">" + _allFiles[myPair.Key].size + "</span>";
- returnCollection[myPair.Key] = myTempOneFile;
- }
- }
- else
- {
- myTempOneFile.lastDate = _allFiles[myPair.Key].lastDate;
- myTempOneFile.size = _allFiles[myPair.Key].size;
- returnCollection["<span style=\"color:red;\">" + myPair.Key + "</span>"] = myTempOneFile;
- }
- }
- return returnCollection;
- }
- }
public struct OneFile
{
public String size;
public String lastDate;
}
///<summary>This class is used for hard drive methods</summary>
///<remarks>
///Contains method for hard drive snapshot, comparing hard drive snapshot and incrementing the number of scaned files
///</remarks>
class DriveAccess
{
/// <summary>
/// StringCollection containing the scaned folder paths
/// </summary>
//private static String[,] _allFiles;
Dictionary<String, OneFile> _allFiles;
public Dictionary<String, OneFile> allFiles
{
get { return _allFiles; }
set { _allFiles = value; }
}
/// <summary>
/// Construct, instanciates the StringCollection
/// </summary>
public DriveAccess()
{
//allFiles = new String[50000,3];
_allFiles = new Dictionary<String, OneFile>();
}
/// <summary>
/// Methods which gets all files and folders in a directory. It uses a Stack which is the best way to
/// deal with non recursive algorithm for scan.
/// </summary>
/// <param name="inDirectory">The directory we want to scan</param>
public void GetAllFiles(String inDirectory)
{
// Define new stack
Stack<String> myStack = new Stack<String>();
// Get all subdirectories in inDirectory
String[] files = Directory.GetFileSystemEntries(inDirectory);
// Define String containing the poped value from stack
String poped;
// We push all subdirectories in the stack
foreach (String fileName in files)
{
myStack.Push(fileName);
}
int i = 0;
// Let's do the main loop
while (myStack.Count > 0)
{
// Pop a value
poped = myStack.Pop();
// If it is a directory
if (Directory.Exists(poped))
{
try
{
// Get it's subdirectories
files = Directory.GetFileSystemEntries(poped);
// Push these subdirectories
foreach (String fileName in files)
{
myStack.Push(fileName);
}
}
catch
{ }
}
// We got a file
else
{
// Get informations about the file
FileInfo myFileInfo = new FileInfo(poped);
// Add it to the StringCollection attribute
//allFiles[i, 0] = poped;
//allFiles[i, 1] = myFileInfo.Length.ToString();
//allFiles[i, 2] = myFileInfo.LastWriteTime.ToString();
//i++;
OneFile myOneFile;
myOneFile.size = myFileInfo.Length.ToString();
myOneFile.lastDate = myFileInfo.LastWriteTime.ToString();
_allFiles[poped] = myOneFile;
// Number of scaned files and directories ++
incNum();
}
}
}
/// <summary>
/// Compares two StringCollections and returns the differences between these StringCollections
/// </summary>
/// <param name="inStringCollec">One of the StringCollection we want to compare</param>
/// <returns>Differences between the two StringCollections</returns>
public Dictionary<String, OneFile> compare(Dictionary<String, OneFile> inStringCollec)
{
// Define the StringCollection we will return
Dictionary<String, OneFile> returnCollection = new Dictionary<String, OneFile>();
OneFile myTempOneFile;
// Foreach String into one of the String[,]
foreach(KeyValuePair<String, OneFile> myPair in _allFiles)
{
if (inStringCollec.ContainsKey(myPair.Key))
{
if (inStringCollec[myPair.Key].lastDate != myPair.Value.lastDate)
{
myTempOneFile.lastDate = "<span style=\"color:red;\">" + _allFiles[myPair.Key].lastDate + "</span>";
myTempOneFile.size = _allFiles[myPair.Key].size;
returnCollection[myPair.Key] = myTempOneFile;
}
if (inStringCollec[myPair.Key].size != myPair.Value.size)
{
myTempOneFile.lastDate = _allFiles[myPair.Key].lastDate;
myTempOneFile.size = "<span style=\"color:red;\">" + _allFiles[myPair.Key].size + "</span>";
returnCollection[myPair.Key] = myTempOneFile;
}
}
else
{
myTempOneFile.lastDate = _allFiles[myPair.Key].lastDate;
myTempOneFile.size = _allFiles[myPair.Key].size;
returnCollection["<span style=\"color:red;\">" + myPair.Key + "</span>"] = myTempOneFile;
}
}
return returnCollection;
}
}