@@ -27,7 +27,7 @@ namespace cli {
2727 print_help (true );
2828 }
2929
30- void list_all_files (std::filesystem::path &root_path, std::vector <std::filesystem::path> *files, XorCryptor::Mode &mode) {
30+ void list_all_files (std::filesystem::path &root_path, std::map <std::filesystem::path, uint8_t > *files, XorCryptor::Mode &mode) {
3131 std::queue<std::filesystem::path> queue;
3232 queue.push (root_path);
3333 while (!queue.empty ()) {
@@ -41,8 +41,10 @@ namespace cli {
4141 continue ;
4242 }
4343 if (entry.is_regular_file ()) {
44- if (mode == XorCryptor::Mode::DECRYPT && entry.path ().extension () == " .xrc" ) files->push_back (entry.path ());
45- if (mode == XorCryptor::Mode::ENCRYPT && entry.path ().extension () != " .xrc" ) files->push_back (entry.path ());
44+ if (mode == XorCryptor::Mode::DECRYPT && entry.path ().extension () == " .xrc" )
45+ (*files)[std::filesystem::absolute (entry.path ())]++;
46+ if (mode == XorCryptor::Mode::ENCRYPT && entry.path ().extension () != " .xrc" )
47+ (*files)[std::filesystem::absolute (entry.path ())]++;
4648 }
4749 }
4850 } catch (std::exception &e) {
@@ -77,8 +79,8 @@ namespace cli {
7779 [[nodiscard]] XorCryptor::Mode get_mode () const { return mode; }
7880
7981 static CmdArgs *parse_args (std::vector<std::string> &args) {
80- auto *file_args = new std::vector<std::filesystem::path>(),
81- *files = new std::vector <std::filesystem::path>();
82+ auto *file_args = new std::vector<std::filesystem::path>();
83+ auto *file_unq = new std::map <std::filesystem::path, uint8_t >();
8284
8385 XorCryptor::Mode mode = XorCryptor::Mode::INVALID;
8486 bool preserve_src = false , recursive = false , verbose = false ;
@@ -118,29 +120,38 @@ namespace cli {
118120 std::cout << " Retrieving files ...\n " ;
119121 for (auto &path : *file_args) {
120122 if (std::filesystem::is_regular_file (path)) {
121- if (mode == XorCryptor::Mode::DECRYPT && path.extension () == " .xrc" ) files-> push_back ( path);
122- if (mode == XorCryptor::Mode::ENCRYPT && path.extension () != " .xrc" ) files-> push_back ( path);
123+ if (mode == XorCryptor::Mode::DECRYPT && path.extension () == " .xrc" ) (*file_unq)[ std::filesystem::absolute ( path)]++ ;
124+ if (mode == XorCryptor::Mode::ENCRYPT && path.extension () != " .xrc" ) (*file_unq)[ std::filesystem::absolute ( path)]++ ;
123125 }
124126 if (std::filesystem::is_directory (path)) {
125127 if (recursive) {
126- list_all_files (path, files , mode);
128+ list_all_files (path, file_unq , mode);
127129 } else {
128130 for (const auto &entry : std::filesystem::directory_iterator (path)) {
129131 if (entry.is_directory ()) continue ;
130132 if (entry.is_regular_file ()) {
131- if (mode == XorCryptor::Mode::DECRYPT && entry.path ().extension () == " .xrc" ) files->push_back (entry.path ());
132- if (mode == XorCryptor::Mode::ENCRYPT && entry.path ().extension () != " .xrc" ) files->push_back (entry.path ());
133+ if (mode == XorCryptor::Mode::DECRYPT && entry.path ().extension () == " .xrc" )
134+ (*file_unq)[std::filesystem::absolute (entry.path ())]++;
135+ if (mode == XorCryptor::Mode::ENCRYPT && entry.path ().extension () != " .xrc" )
136+ (*file_unq)[std::filesystem::absolute (entry.path ())]++;
133137 }
134138 }
135139 }
136140 }
137141 }
138- if (files ->empty ()) {
142+ if (file_unq ->empty ()) {
139143 print_error (" No " + std::string (mode == XorCryptor::Mode::DECRYPT ? " .xrc " : " " ) + " file(s) found" );
140144 return nullptr ;
141145 }
142- std::cout << files->size () << (mode == XorCryptor::Mode::DECRYPT ? " .xrc" : " " ) << " file(s) found\n " ;
143- return new CmdArgs (files, preserve_src, verbose, mode);
146+ std::cout << file_unq->size () << (mode == XorCryptor::Mode::DECRYPT ? " .xrc" : " " ) << " file(s) found\n " ;
147+
148+ auto *files = new std::vector<std::filesystem::path>();
149+ for (auto &file : *file_unq) files->emplace_back (file.first );
150+ auto *res = new CmdArgs (files, preserve_src, verbose, mode);
151+
152+ delete file_args;
153+ delete file_unq;
154+ return res;
144155 }
145156 };
146157
0 commit comments