/// <summary> /// Constructor /// </summary> /// <param name="parentFolder">Parent folder</param> /// <param name="name">The name of the folder</param> /// <param name="modifiedDateTime">The modified date/time</param> public FolderItem(FolderItem parentFolder, string name, DateTime modifiedDateTime) : base(parentFolder, name, 0, modifiedDateTime) { // A folder retrieves its icons on startup, because folders are relatively rare this.RetrieveIcons(); }
public FileItem(FolderItem parentFolder, string name, long size, DateTime modifiedDateTime) : base(parentFolder, name, size, modifiedDateTime) { }
/// <summary> /// Compare this folder to another one. Set all states of files and folders /// INCLUDING OUR OWN STATE /// </summary> /// <param name="otherFolder"></param> public void CompareTo(FolderItem otherFolder) { // Assume the lowest state for each CompareState myState = CompareState.Unchanged; CompareState otherState = CompareState.Unchanged; //if (this.files.Count == 0 && otherFolder.files.Count == 0) //{ // myState = CompareState.Equal; // otherState = CompareState.Equal; //} //else //{ // Iterate over our own files, comparing each foreach (FileItem file in this.files) { string name = file.Name; FileItem otherFile = otherFolder.FindFileByName(name); if (otherFile == null) { // Hey - no equivalent of our file found! Upgrade our own state to Added: myState = CompareState.Added; } else { file.CompareTo(otherFile); // If the file has a more important state than we do, update our state if (file.State > myState) { myState = file.State; } } } if (myState == CompareState.Added) { otherState = CompareState.Older; } else { // Update the other folder's state based on its files: foreach (FileItem file in otherFolder.files) { if (file.State > otherState) { otherState = file.State; } } } //} // Compare all folders foreach (FolderItem folder in this.folders) { string name = folder.Name; FolderItem folder2 = otherFolder.FindFolderByName(Path.GetFileName(name)); if (folder2 != null) { // Compare the two folders: folder.CompareTo(folder2); // Upgrade our own state if we have to: if (folder.State > myState) { myState = folder.State; } } } if (myState == CompareState.Added) { otherState = CompareState.Older; } else { // Update the other folder's state based on its folders: foreach (FolderItem folder in otherFolder.folders) { if (folder.State > otherState) { otherState = folder.State; } } } // Now update our own and the other folder's states: this.State = myState; otherFolder.State = otherState; }