/** Runs the thread for file identification analysis */ public void run() { //Let AnalysisController know that anlaysis has started myAnalysisController.setAnalysisStart(); //DateTime startTime = new DateTime(); for (int fileNum = 0; fileNum < myFileCollection.getNumFiles() && !myAnalysisController.isAnalysisCancelled(); fileNum++) { IdentificationFile idFile = myFileCollection.getFile(fileNum); String idFileName = idFile.getFilePath(); DateTime startRead = new DateTime(); IByteReader testFile = null; try { testFile = AbstractByteReader.newByteReader(idFile); } catch (System.OutOfMemoryException e) //OutOfMemoryError e) { testFile = AbstractByteReader.newByteReader(idFile, false); testFile.SetErrorIdentification(); testFile.SetIdentificationWarning("The application ran out of memory while loading this file (" + e.ToString() + ")"); } DateTime endRead = new DateTime(); readTime += (endRead.TimeOfDay.Milliseconds - startRead.TimeOfDay.Milliseconds); // was getTime() if (!testFile.IsClassified()) { //int id = theFile.getInternalSignature(0).getByteSequence(0).getSubSequence(1).getShift(16); //testFile.runFileIdentification(theFile); DateTime startAlgo = new DateTime(); try { mySigFile.runFileIdentification(testFile); } catch (Exception e) { testFile.SetErrorIdentification(); testFile.SetIdentificationWarning("Error during identification attempt: " + e.ToString()); } DateTime endAlgo = new DateTime(); algoTime += (endAlgo.TimeOfDay.Milliseconds - startAlgo.TimeOfDay.Milliseconds); // was getTime() } /************** print out results ***************/ //display the hits debugDisplayHits(testFile, idFileName); //Record the fact that another file has completed myAnalysisController.incrNumCompletedFile(); } //DateTime endTime = new DateTime(); //Let AnalysisController know that anlaysis is complete myAnalysisController.setAnalysisComplete(); }
/** * Adds an element/elements to the collection * If filepath is a path to file then add that file * If filepath is a folder path then add contents of the folder * * @param theFile Filepath of file or folder * @param isRecursive if true add all subfolders and subsubfolders , etc */ public void addFile(string theFile, bool isRecursive) { if (UrlByteReader.isURL(theFile)) { if (!this.isDuplicate(theFile)) { //File object is a URL: add if it isn't a duplicate myFiles.Add(new IdentificationFile(theFile)); } return; } if (InputStreamByteReader.isInputStream(theFile)) { if (!this.isDuplicate(theFile)) { // File is a the input stram: add if it isn't a duplicate myFiles.Add(new IdentificationFile(theFile)); } } try { //java.io.File f = new java.io.File(theFile); System.IO.FileInfo f = new System.IO.FileInfo(theFile); //Is file object a directory or file? if (System.IO.Directory.Exists(theFile)) //f.isDirectory()) { //File object is a directory/folder //Iterate through directory ,create IdentificationFile objects //and add them to the collection //java.io.File[] folderFiles = f.listFiles(); System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(theFile); System.IO.FileInfo[] folderFiles = d.GetFiles(); int numFiles = 0; try { numFiles = folderFiles.Length; } catch (Exception) { MessageDisplay.GeneralWarning("Unable to read directory " + theFile + "\nThis may be because you do not have the correct permissions."); } for (int m = 0; m < numFiles; m++) { if (System.IO.Directory.Exists(folderFiles[m].FullName)) //folderFiles[m].isFile()) { //If file exists and not duplicate then add if (!this.isDuplicate(folderFiles[m].FullName)) { IdentificationFile idFile = new IdentificationFile(folderFiles[m].FullName); myFiles.Add(idFile); } } else if (System.IO.Directory.Exists(folderFiles[m].FullName) && isRecursive) { //If subdirectory found and recursive is on add contents of that folder addFile(folderFiles[m].FullName, isRecursive); } } } else if (!System.IO.Directory.Exists(f.FullName)) //f.isFile()) { if (!this.isDuplicate(f.FullName)) { //File object is a File then add file if it isn't a duplicate IdentificationFile idFile = new IdentificationFile(f.FullName); myFiles.Add(idFile); } } } catch (Exception e) { MessageDisplay.GeneralWarning("The following error occured while adding " + theFile + ":\n" + e.ToString()); } }
/** * Add a new identification file to list (used when reading in an XML file collection file) * @param theFile A new IdentificationFile object which will be populated from file */ public void addIdentificationFile(IdentificationFile theFile) { myFiles.Add(theFile); }