Skip to content

Commit

Permalink
Modified FilesIndexer to not show objects with "hidden"-flag by default.
Browse files Browse the repository at this point in the history
changed version to 0.3.1.0
  • Loading branch information
derco0n committed Nov 23, 2018
1 parent b540c91 commit 73ef082
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 34 deletions.
Binary file modified .vs/Co0nUtilZ/DesignTimeBuild/.dtbcache
Binary file not shown.
Binary file modified .vs/Co0nUtilZ/v15/.suo
Binary file not shown.
Binary file modified .vs/Co0nUtilZ/v15/Server/sqlite3/storage.ide
Binary file not shown.
139 changes: 107 additions & 32 deletions Co0nUtilZ/C_FilesIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class C_FilesIndexer
public Thread _SearchThread;
private String _Searchfor="";
private Boolean _SearchForNameOnly = true;
private Boolean _includehiddenelement=false; //Also find hidden files?

//private List<String> foldersprocessed = new List<string>(); //DEBUG

Expand All @@ -47,9 +48,11 @@ public class C_FilesIndexer
/// Creates a new FileSearcher-instance
/// </summary>
/// <param name="Pathname">Path to Searchbase-Directory</param>
/// <param name="showhiddenfiles">Include hiddenfiles in result (Default: FALSE)</param>
/// <param name="Recurse">NOT IN USE (YET) (Default:TRUE)</param>
public C_FilesIndexer(String Pathname, Boolean Recurse = true)
public C_FilesIndexer(String Pathname, Boolean showhiddenfiles=false, Boolean Recurse = true)
{
this._includehiddenelement = showhiddenfiles;
this._Pathname = Pathname;
this._Recurse = Recurse;
}
Expand Down Expand Up @@ -140,6 +143,30 @@ private bool IsSymbolic(string path)
return pathInfo.Attributes.HasFlag(FileAttributes.ReparsePoint);
}

/// <summary>
/// Checks if Hidden-Attribute is set
/// </summary>
/// <param name="path">PATH to Fiile or Folder</param>
/// <returns>True if object is hidden, otherwise false</returns>
private bool Ishidden(string path)
{
FileInfo pathInfo = new FileInfo(path);

/*
//DEBUG
if (pathInfo.Attributes.HasFlag(FileAttributes.ReparsePoint))
{
return true;
}
else
{
return false;
}
*/

return pathInfo.Attributes.HasFlag(FileAttributes.Hidden);
}

/// <summary>
/// Parses a Directory
/// </summary>
Expand All @@ -157,20 +184,46 @@ private void parseDirectoryWorker(String currentfolder, String Searchpattern)
{
// Add files matching pattern to result
List<C_FilesIndexerElement> newfilObjs = new List<C_FilesIndexerElement>();
bool newobjectsreallyfound = false; //This indicates that an event should be raised or not

foreach (String fil in newFiles)
{
newfilObjs.Add(new C_FilesIndexerElement(fil, C_FilesIndexerElement.TYPE_FILE));
}
if (!this._includehiddenelement)
{
//Hidden objects should not be shown. first check if attribute is set...
if (!this.Ishidden(fil))
{//Object is not hidden...
newfilObjs.Add(new C_FilesIndexerElement(fil, C_FilesIndexerElement.TYPE_FILE)); //Add object to result
newobjectsreallyfound = true;
}
/*
else
{
//Object is hidden and hidden objects should not be shown....
}
*/
}
else
{//Hidden objects should also be shown. no further checking necessary...
newfilObjs.Add(new C_FilesIndexerElement(fil, C_FilesIndexerElement.TYPE_FILE)); //Add object to result
newobjectsreallyfound = true;
}

lock (this._founditems)
{
this._founditems.AddRange(newfilObjs);
}
//New folder found
if (this.OnItemsFound != null)

if (newobjectsreallyfound /*Will be false if all found items are hidden*/)
{
//this.OnItemsFound(this, newFiles);
this.OnItemsFound(this, newfilObjs);

lock (this._founditems)
{
this._founditems.AddRange(newfilObjs);
}
//New folder found
if (this.OnItemsFound != null)
{
//this.OnItemsFound(this, newFiles);
this.OnItemsFound(this, newfilObjs);
}
}

}
Expand Down Expand Up @@ -202,42 +255,66 @@ private void parseDirectoryWorker(String currentfolder, String Searchpattern)

List<String> newFolders = new List<string>();
newFolders.AddRange(matchingfoldersInCurrent);



if (newFolders.Count() > 0)
{//New folder found
List<C_FilesIndexerElement> newFolObjs = new List<C_FilesIndexerElement>();

bool newobjectsreallyfound = false; //This indicates that an event should be raised or not

// Add Folders matching searchpattern to result

foreach (String fol in newFolders)
{
C_FilesIndexerElement temp = new C_FilesIndexerElement(fol, C_FilesIndexerElement.TYPE_FOLDER);
newFolObjs.Add(temp);
if (!this._includehiddenelement)
{
//Hidden objects should not be shown. first check if attribute is set...
if (!this.Ishidden(fol))
{//Object is not hidden...
C_FilesIndexerElement temp = new C_FilesIndexerElement(fol, C_FilesIndexerElement.TYPE_FOLDER); //Add object to result
newFolObjs.Add(temp);
newobjectsreallyfound = true;
}
/*
else
{
//Object is hidden and hidden objects should not be shown....
}
*/
}
else
{//Hidden objects should also be shown. no further checking necessary...
C_FilesIndexerElement temp = new C_FilesIndexerElement(fol, C_FilesIndexerElement.TYPE_FOLDER); //Add object to result
newFolObjs.Add(temp);
newobjectsreallyfound = true;
}

}


if (this.OnItemsFound != null)
if (newobjectsreallyfound /*Will be false if all found items are hidden*/)
{
//this.OnItemsFound(this, newFolders);
try
{
this.OnItemsFound(this, newFolObjs);
}
catch (Exception ex)

if (this.OnItemsFound != null)
{
if (this.OnErrorOccured != null)
//this.OnItemsFound(this, newFolders);
try
{
this.OnErrorOccured(this, ex.ToString());
this.OnItemsFound(this, newFolObjs);
}
catch (Exception ex)
{
if (this.OnErrorOccured != null)
{
this.OnErrorOccured(this, ex.ToString());
}
}
}
}

lock (this._founditems)
{
this._founditems.AddRange(newFolObjs); // Add Folders matching searchpattern to result
lock (this._founditems)
{
this._founditems.AddRange(newFolObjs); // Add Folders matching searchpattern to result
}
}
}

Expand All @@ -246,10 +323,8 @@ private void parseDirectoryWorker(String currentfolder, String Searchpattern)

//Alle Unterordner ermitteln um diese der Suche hinzuzufügen
var foldersInCurrent = System.IO.Directory.EnumerateDirectories(currentfolder).AsParallel(); // Alle Unterordner des aktuellen Ordners ermitteln...
//var foldersInCurrent = System.IO.Directory.EnumerateDirectories(currentfolder, "*").AsParallel().Where(f => !new FileInfo(f).Attributes.HasFlag(FileAttributes.ReparsePoint)); // Alle Unterordner des aktuellen Ordners ermitteln... //This is much slower than checking afterwards

//String[] DEBUG = foldersInCurrent.ToArray(); //DEBUG



foreach (string subdir in foldersInCurrent)
//foreach (string subdir in DEBUG) //DEBUG
{
Expand Down
4 changes: 2 additions & 2 deletions Co0nUtilZ/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.3.1.0")]
[assembly: AssemblyFileVersion("0.3.1.0")]
Binary file modified Co0nUtilZ/bin/Debug/Co0nUtilZ.dll
Binary file not shown.
Binary file modified Co0nUtilZ/bin/Debug/Co0nUtilZ.pdb
Binary file not shown.
Binary file modified Co0nUtilZ/bin/Release/Co0nUtilZ.dll
Binary file not shown.
Binary file modified Co0nUtilZ/bin/Release/Co0nUtilZ.pdb
Binary file not shown.
Binary file modified Co0nUtilZ/obj/Debug/Co0nUtilZ.dll
Binary file not shown.
Binary file modified Co0nUtilZ/obj/Debug/Co0nUtilZ.pdb
Binary file not shown.
Binary file modified Co0nUtilZ/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file modified Co0nUtilZ/obj/Release/Co0nUtilZ.dll
Binary file not shown.
Binary file modified Co0nUtilZ/obj/Release/Co0nUtilZ.pdb
Binary file not shown.

0 comments on commit 73ef082

Please sign in to comment.