/// <summary> Fill the contents list window with files's own Icons, given a directory name path </summary> private void AddImagesExtsToFileLists(string directoryName) { contentsFileList.Clear(); //part 2: resetList all subfiles, match the extension and find the icon. foreach (string file in Directory.GetFiles(directoryName)) { var fileAttribs = File.GetAttributes(file); if ((fileAttribs & SharedHelper.SyncSettingstoInvisibleFlag()) != 0) { continue; //skip the rest if its supposed to be "invisible" based on the mask } string justName = Path.GetFileName(file); SharedHelper.CurrExten = Path.GetExtension(file); if ((SharedHelper.CurrExten != ".lnk")) //if its not a shortcut { //if not already in the resetList, then add it if (filextlist.FindLastIndex(SharedHelper.FindCurExt) == -1) { filextlist.Add(SharedHelper.CurrExten); //call NativeExtractIcon to get the filesystem icon of the filename imageListFiles.Images.Add(SharedHelper.CurrExten, NativeExtractIcon.GetIcon(file, true)); } } else //if it is a shortcut, grab icon directly. { imageListFiles.Images.Add(justName, NativeExtractIcon.GetIcon(file, true)); } contentsFileList.Add(justName); } }
/// <summary> /// Very long function that does a simple task. Read in the options the user set for the operation, and /// Decide on the timestamp it should use, by the end we will have a single object with 3 times. /// This will need to be hit with broad strokes if we attempt to do any more work on the program. /// </summary> internal NameDateObj DecideWhichTimeMode2(string directoryPath) { var extractlist = new List <string>(); var timelist = new List <NameDateObj>(); if (ObtainParseSpecifiedTimeGUIBoxes()) { return(thingtoreturn); } //Begin checking Conditional for which file is newest oldest etc if (!gui.radioGroupBox3UseTimeFrom) { return(thingtoreturn); } //decide if they wanted to use time from subfile or subdir if (gui.radioButton1_useTimefromFile) { try { // Get List of the subfiles (full path) extractlist.AddRange(from subFile in Directory.GetFiles(directoryPath) let fileAttribs = File.GetAttributes(subFile) where (fileAttribs & SharedHelper.SyncSettingstoInvisibleFlag()) == 0 select Path.Combine(directoryPath, subFile)); } // catch failure of GetAttributes catch (FileNotFoundException ex) { MessageBox.Show( "Error getting attributes of a file in '" + directoryPath + "': \r\n\r\n" + ex.Message, @"PEBKAC Error ", MessageBoxButtons.OK, MessageBoxIcon.Error); } // catch failure of GetFiles catch (UnauthorizedAccessException) { } //show nothing because this is normal for this method when encountering inaccessible files } else if (gui.radioButton2_useTimefromSubdir) { try { // Get List of the subdirs (full path) extractlist.AddRange(Directory.GetDirectories(directoryPath).Select(subDirectory => Path.Combine(directoryPath, subDirectory))); } // catch failure from GetDirs catch (UnauthorizedAccessException) { } //show nothing because this is normal for this method when encountering inaccessible dirs } // ## Exit out early: // if the list is empty, theres nothing to do, then return an empty object.????? if (extractlist.Count == 0) { return(thingtoreturn); } // ---------------------------------------------------------------------------------// // ## MID WAY POINT ## // We have our first list and now we apply it to the 3 other CMA lists per all the files // And where we actually decide whether to keep our time or use the new time. // ---------------------------------------------------------------------------------// foreach (string fullpath in extractlist) { var decidetemp = new NameDateObj { Name = fullpath }; //grab all 3 times and put them in a decidetemp object try { decidetemp.Created = File.GetCreationTime(fullpath); // File Class works on dirs also decidetemp.Modified = File.GetLastWriteTime(fullpath); decidetemp.Accessed = File.GetLastAccessTime(fullpath); //add the temp object to the list of objects timelist.Add(decidetemp); } catch (UnauthorizedAccessException) { } } //make 3 new lists, one for each date containing every NameDateObj var creationtimelist = new List <DateTime?>(); var modtimelist = new List <DateTime?>(); var accesstimelist = new List <DateTime?>(); //populate the new seperated lists with the times from the combinedobject list (timelist) foreach (NameDateObj timeobject in timelist) { creationtimelist.Add((DateTime?)timeobject.Created); modtimelist.Add((DateTime?)timeobject.Modified); accesstimelist.Add((DateTime?)timeobject.Accessed); } //Make a new list of the lists we just made (Collection initializer) var threetimelists = new List <List <DateTime?> > { creationtimelist, modtimelist, accesstimelist }; //Instantiate 3 new vars as a new class that processes the min and max date from the 3 lists we just made var cre = new DateMinMaxNewOld(creationtimelist); var mod = new DateMinMaxNewOld(modtimelist); var acc = new DateMinMaxNewOld(accesstimelist); ////Create 2 lists(min and max), containing the 3 min/max dates. //DateTime?[] minarray = { cre.minDate, mod.minDate, acc.minDate }; //DateTime?[] maxarray = { cre.maxDate, mod.maxDate, acc.maxDate }; ////Instantiate themin/themax as the new class that calculates the min and max date from the 3 dates above. //var themin = new DatesNewestOldest(new List<DateTime?>(minarray)); //var themax = new DatesNewestOldest(new List<DateTime?>(maxarray)); ////Keep track of the min/max indexes in this 1,2,3 format too. //int[] minindexesarray = { cre.minIndex, mod.minIndex, acc.minIndex }; //int[] maxindexesarray = { cre.maxIndex, mod.maxIndex, acc.maxIndex }; string filenameused = ""; //var dateToUse = new DateTime?(); //Decide which to use. if (gui.radioButton1Oldest) { //mode a: set ALL attributes to the oldest date of whichever attribute was oldest. // dateToUse = (DateTime?)minarray[themin.minIndex]; // filenameused = timelist[minindexesarray[themin.minIndex]].Name; // thingtoreturn.Created = dateToUse; // thingtoreturn.Modified= dateToUse; // thingtoreturn.Accessed = dateToUse; //mode b: the more desirable mode: //set each attribute to OLDest date from EACH attribute thingtoreturn.Name = "Mode 2: Three Different Filenames"; // note to self. thingtoreturn.Created = cre.MinDate; thingtoreturn.Modified = mod.MinDate; thingtoreturn.Accessed = acc.MinDate; } //the above comments obviously can apply to newer mode also with a small edit. else if (gui.radioButton2Newest) { //set each attribute to NEWest date from EACH attribute thingtoreturn.Name = "Mode 2: Three Different Filenames"; // note to self. thingtoreturn.Created = cre.MaxDate; thingtoreturn.Modified = mod.MaxDate; thingtoreturn.Accessed = acc.MaxDate; } else if (gui.radioButton3Random) { //Mode A: (old) - removed the following 4 radio buttons //pick a subfile/dir at random, then pick an attribute(C,M,A) at random // int randomindex = random.Next(0, timelist.Count); // filenameused = timelist[randomindex].Name; // if (radioButton1_setfromCreation.Checked) // thingtoreturn.Created = (DateTime?)threetimelists[0][randomindex]; // if (radioButton2_setfromModified.Checked) // thingtoreturn.Modified = (DateTime?)threetimelists[1][randomindex]; // if (radioButton3_setfromAccessed.Checked) // thingtoreturn.Accessed = (DateTime?)threetimelists[2][randomindex]; // if (radioButton4_setfromRandom.Checked) // { // int cmarandomize = random.Next(0, 3); // dateToUse = (DateTime?)threetimelists[cmarandomize][randomindex]; // if (cmarandomize == 0) // thingtoreturn.Created = dateToUse; // else if (cmarandomize == 1) // thingtoreturn.Modified = dateToUse; // else if (cmarandomize == 2) // thingtoreturn.Accessed = dateToUse; // } //Mode B: (current) //Pick a subfile/dir at random, copy all 3 attributes from it, to the return object. int randomindex = random.Next(0, timelist.Count); filenameused = timelist[randomindex].Name; thingtoreturn.Created = threetimelists[0][randomindex]; thingtoreturn.Modified = threetimelists[1][randomindex]; thingtoreturn.Accessed = threetimelists[2][randomindex]; } //Set the thingtoReturn Name to what we just determined. thingtoreturn.Name = filenameused; return(thingtoreturn); }