WatchForFile mw =
new WatchForFile
();
List<WatchForFile> monitorThese =
new List<WatchForFile>
();
List <String> extensions =
new List<String>
(textBoxOtherextensions.
Text.
Split(','));
/*string[] extensionsarray */
// extensions.AddRange((int).Length)
foreach (String s in extensions){
WatchForFile mwf=
new WatchForFile
();
mwf.watchThisFile(Properties.Settings.Default.Path, "*." + s);
monitorThese.Add(mwf);
}
public void OnRenamed(object sender, FileSystemEventArgs e)
{
try
{
FileInfo thisFile =
new FileInfo
(e.
FullPath);
System.Windows.MessageBox.Show("Filens Directory.Name = " +thisFile.Directory.Name+Environment.NewLine+"Filens thisFile.DirectoryName = " + thisFile.DirectoryName);
System.
IO.
DirectoryInfo myPath =
new System.
IO.
DirectoryInfo(thisFile.
DirectoryName);
FileInfo[] filearray = myPath.GetFiles();
List<FileInfo> dirFiles =
new List<FileInfo>
();
foreach(FileInfo f in filearray){
dirFiles.Add(f);
}
FileInfo utExtension = dirFiles.Find(delegate(FileInfo f) { return f.Extension == "!ut"; });
//Person myLocatedObject = myList.Find(delegate(Person p) {return p.ID == 1; }); // Best way for finding an object.
if (utExtension != null)
{
Properties.Settings.Default.Log += Environment.NewLine + "Change detected, but !ut extension found. Doing nothing...";
}
else
{
Properties.Settings.Default.Log += "Change detected, and no !ut extensions found. Trying to unzip...";
SevenZipExtractor.SetLibraryPath(@"..\7z.dll");
string fileName = e.FullPath.ToString();
string directory = Properties.Settings.Default.Destination+thisFile.Directory.Name;
var extractor =
new SevenZipExtractor
(fileName
);
extractor.
Extracting +=
new EventHandler<ProgressEventArgs>
(extr_Extracting
);
extractor.
FileExtractionStarted +=
new EventHandler<FileInfoEventArgs>
(extr_FileExtractionStarted
);
extractor.
FileExists +=
new EventHandler<FileOverwriteEventArgs>
(extr_FileExists
);
extractor.
ExtractionFinished +=
new EventHandler<EventArgs>
(extr_ExtractionFinished
);
extractor.BeginExtractArchive(directory);
}
}
catch (Exception error)
{
System.Windows.MessageBox.Show("error: "+error.ToString());
}
}
public class WatchForFile
{
FileSystemWatcher fmw =
new FileSystemWatcher
();
public string watchThisFile(string path, string filter)
{
try
{
fmw.IncludeSubdirectories = true;
fmw.Filter = filter;
fmw.Path = path;
fmw.NotifyFilter = NotifyFilters.FileName;
fmw.EnableRaisingEvents = true;
// Add event handlers.
fmw.
Renamed +=
new RenamedEventHandler
(OnRenamed
);
return "Started Monitoring!";
}
catch (Exception error) { return error.ToString(); }
}
public string path
{
get { return fmw.Path; }
}
public string filter { get { return fmw.Filter; } }
public virtual void OnRenamed(object sender, FileSystemEventArgs e){}
}