Skip to content

Commit

Permalink
v2.0 fixed all known bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gisbert12843 committed Sep 9, 2022
1 parent facacc8 commit e472c46
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 41 deletions.
8 changes: 4 additions & 4 deletions WinXSearch-Setup/WinXSearch-Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:WinXSearch"
"ProductCode" = "8:{B268359F-6E89-4CF5-90EF-E9E4A45EFD58}"
"PackageCode" = "8:{110CEF96-EB39-484A-A28B-90B98926855D}"
"ProductCode" = "8:{F619C0D7-BD44-41E7-A333-0DFDF47AB0F7}"
"PackageCode" = "8:{A2B75196-EF68-49AC-BB2C-B2179C028DFE}"
"UpgradeCode" = "8:{EEB88A61-C181-477D-A824-C2DC4FB69917}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.1"
"ProductVersion" = "8:2.0"
"Manufacturer" = "8:Kai Oestreich"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down Expand Up @@ -603,7 +603,7 @@
"Condition" = "8:"
"Transitive" = "11:FALSE"
"ValueTypes" = "3:1"
"Value" = "8:[TARGETDIR]WinXSearch.exe %w"
"Value" = "8:[TARGETDIR]WinXSearch.exe \"%W\""
}
}
}
Expand Down
97 changes: 63 additions & 34 deletions functions.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
#include "functions.h"
#include "conversions.h"


int processedFiles = 0;
int processedFolders = 0;

bool skipFiles(std::filesystem::recursive_directory_iterator &iter, std::error_code &ec, int &p_free_threads)
{
for (int i = 0; i < p_free_threads - 1; i++) //skips x files every turn so all files only get processesed by one thread ever
iter.increment(ec);
return true;
}

//given a percentage it prints a nice formatted progressbar to the console
void printProgress(double& percentage)
{
auto start = std::chrono::high_resolution_clock::now();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = duration_cast<std::chrono::microseconds>(stop - start);

while (percentage < 90)
while (percentage < 98)
{
stop = std::chrono::high_resolution_clock::now();
duration = duration_cast<std::chrono::microseconds>(stop - start);
Expand Down Expand Up @@ -136,9 +144,9 @@ void display(
int processedFiles,
int processedFolders,
auto seconds,
std::vector<std::filesystem::directory_entry> vec_folder_path,
std::vector<std::filesystem::directory_entry> vec_content_path,
std::vector<std::filesystem::directory_entry> vec_file_path)
std::vector<std::filesystem::directory_entry> &vec_folder_path,
std::vector<std::filesystem::directory_entry> &vec_content_path,
std::vector<std::filesystem::directory_entry> &vec_file_path)

{
std::vector<int> vec_to_be_opened; //storing the identifier for files/folders to be opened
Expand Down Expand Up @@ -226,24 +234,45 @@ void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const s
std::vector<std::filesystem::directory_entry>& vec_file_path)
{
int frickinFilesCounter = 0;
int skippedFilesCounter = 0;

int skipper = 0;
int onetime_skipped = 0;
// Iterates over every file/folder in the path of the executable and its subdiretories

for (auto& dirEntry : std::filesystem::recursive_directory_iterator(pathToFolder))


auto iter = std::filesystem::recursive_directory_iterator(pathToFolder, std::filesystem::directory_options::skip_permission_denied);
auto end_iter = std::filesystem::end(iter);
auto ec = std::error_code();
std::filesystem::directory_entry dirEntry;

for (int i = 0; i < p_i - 1; i++) //onetime skip for each thread (first thread doesnt skip a file ; the 5. does skip 4 files
iter.increment(ec);

for (; iter != end_iter; iter.increment(ec))
{
dirEntry = std::filesystem::directory_entry(iter->path());
if (ec)
{
continue;
}
//std::wcout << dirEntry << "\n";
// The rest of your loop code here...


// p_i 0-5
// free_threads 6

//case : p_i = 1

if (onetime_skipped < p_i-1)
{
onetime_skipped++;
continue;
}
//if (onetime_skipped < p_i - 1)
//{
// onetime_skipped++;
// continue;
//}


if (skipper < p_free_threads)
{
if (skipper != 0)
Expand All @@ -252,11 +281,10 @@ void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const s
continue;
}
skipper++;

}
if (skipper == p_free_threads)
skipper = 1;
// The Above Block handles that the programm only processes every file just once, by skipping x times at the start (x = 1, if it is the first created thread; = 2 if its the second
//The Above Block handles that the programm only processes every file just once, by skipping x times at the start (x = 1, if it is the first created thread; = 2 if its the second


//Skips invisible files
Expand All @@ -267,28 +295,20 @@ void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const s
}*/

frickinFilesCounter++;

currentfilecount++;

percentage = currentfilecount / filecount * 100;

bool found = false;

//std::wstring currentPathW = dirEntry.path().c_str();
//std::string currentPath = wide_string_to_string(currentPathW);

//std::cout << currentPath << std::endl;
//std::wcout << currentPathW << endl;
//wcout.flush(); wcout.clear();


if ((pathToFolder == dirEntry.path().wstring()) || dirEntry.is_symlink()) //skip if iterated file is the running executable or a symlink
if ((pathToFolder == dirEntry.path().wstring()) || dirEntry.is_symlink(ec)) //skip if iterated file is the running executable or a symlink
{
continue;
}



bool found = false;
if (std::filesystem::is_directory(dirEntry.path())) // optional: folder as iterated file
{
if (searchFolders == false)
Expand All @@ -307,7 +327,7 @@ void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const s
}
continue;
}
else
else //since its not a directory, it has to be a file
{
for (auto& it : vecSearchValue)
{
Expand All @@ -321,8 +341,6 @@ void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const s
continue;




std::wifstream inputfile;
inputfile.open(dirEntry, std::wifstream::in);
if (inputfile.rdstate() != std::ios_base::goodbit)
Expand Down Expand Up @@ -365,8 +383,9 @@ void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const s
}
continue;
}
}
// big for loop ending
for (int i = 0; i < p_free_threads-1; i++) //skips x files every turn so all files only get processesed by one thread ever
iter.increment(ec);
}// big for loop ending
processedFiles += frickinFilesCounter;
}

Expand All @@ -384,7 +403,7 @@ void startWinXSearch(const std::wstring& pathToFolder, bool searchFolders, bool
if (!(std::filesystem::directory_entry(pathToFolder.c_str()).is_directory()))
{
std::cout << "PATH IS NOT A DIRECTORY!" << std::endl;
std::cin.ignore();
//std::cin.ignore();
exit;
}

Expand All @@ -399,16 +418,25 @@ void startWinXSearch(const std::wstring& pathToFolder, bool searchFolders, bool
double currentfilecount = 0;
double percentage = 0;



std::vector<std::thread>thread_list;


auto iter = std::filesystem::recursive_directory_iterator(pathToFolder, std::filesystem::directory_options::skip_permission_denied);
auto end_iter = std::filesystem::end(iter);
auto ec = std::error_code();


for (const auto& file : std::filesystem::recursive_directory_iterator(pathToFolder)) //answers how many files are present to calculate progress
system("CLS");
std::cout << "Scanning files\n";
for (; iter != end_iter; iter.increment(ec))
{
if (ec)
{
continue;
}
filecount++;

}
system("CLS");

std::thread t1(printProgress, std::ref(percentage));
thread_list.push_back(std::move(t1));
Expand Down Expand Up @@ -438,11 +466,12 @@ void startWinXSearch(const std::wstring& pathToFolder, bool searchFolders, bool

system("CLS");

for (int i = 0; i < thread_list.size(); i++)
for (int i = 1; i < thread_list.size(); i++)
{
if (thread_list.at(i).joinable())
thread_list.at(i).join();
thread_list.at(i).join();
}
thread_list.at(0).join();

auto stop = std::chrono::high_resolution_clock::now();
auto duration = duration_cast<std::chrono::microseconds>(stop - start);
Expand Down
6 changes: 3 additions & 3 deletions functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ void display(
int processedFiles,
int processedFolders,
auto seconds,
std::vector<std::filesystem::directory_entry> vec_folder_path,
std::vector<std::filesystem::directory_entry> vec_content_path,
std::vector<std::filesystem::directory_entry> vec_file_path);
std::vector<std::filesystem::directory_entry>&vec_folder_path,
std::vector<std::filesystem::directory_entry>&vec_content_path,
std::vector<std::filesystem::directory_entry>&vec_file_path);


void big_for_loop(int p_i, int p_free_threads, double& currentfilecount, const std::wstring& pathToFolder, double& percentage, double& filecount, bool& searchFolders, bool& searchContent,
Expand Down
7 changes: 7 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ int wmain(int argc, wchar_t* argv[])

#ifdef NDEBUG
{
//std::cout << wide_string_to_string(std::wstring(argv[0]));
//std::string s = "C:\\Users\\wwwgi\\Music\\New folder";
//s = "C:\\Windows";
//startWinXSearch(StringToWString(s), searchFolders, searchContent, VecSearchValue);

startWinXSearch(argv[1], searchFolders, searchContent, VecSearchValue);
}
#else
{
//std::cout << wide_string_to_string(std::wstring(argv[0]));
std::string s = "C:\\Sciebo";
//s = "C:\\Program Files";


startWinXSearch(StringToWString(s), searchFolders, searchContent, VecSearchValue);
}
Expand Down

0 comments on commit e472c46

Please sign in to comment.