aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-07-29 00:43:28 +0200
committerdec05eba <dec05eba@protonmail.com>2023-07-29 00:43:28 +0200
commit1139e4a16a76d5de64c87b4075ac570914ef192f (patch)
treecba0936de32ce73e28e1946f5631bbcd0951bc9d /src
parent1b3312aae47952caa50f8c5f9ca56b16109d1bd7 (diff)
Ctrl+Shift+S: Create a new name for file instead of replacing existing one
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 3a42906..86d4f8f 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -7992,6 +7992,33 @@ namespace QuickMedia {
}
}
+ static std::string get_unique_filename(Path directory, Path filename) {
+ Path full_filepath = directory;
+ full_filepath.join(filename);
+ if(get_file_type(full_filepath) == FileType::FILE_NOT_FOUND)
+ return full_filepath.data;
+
+ for(int i = 1; i < 100; ++i) {
+ std::string filename_unique = filename.filename_no_ext() + " (" + std::to_string(i) + ")" + filename.ext();
+ Path full_filepath = directory;
+ full_filepath.join(filename_unique);
+ if(get_file_type(full_filepath) == FileType::FILE_NOT_FOUND)
+ return full_filepath.data;
+ }
+
+ full_filepath = directory;
+ char buffer[10];
+ if(generate_random_characters(buffer, sizeof(buffer), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62)) {
+ std::string new_filename = filename.filename_no_ext() + " ";
+ new_filename.append(buffer, sizeof(buffer));
+ new_filename += filename.ext();
+ full_filepath.join(new_filename);
+ } else {
+ full_filepath.join(filename);
+ }
+ return full_filepath.data;
+ }
+
void Program::download_page(std::string url, std::string download_filename, bool no_dialog) {
window.set_title(("QuickMedia - Select where you want to save " + std::string(url)).c_str());
@@ -8087,7 +8114,8 @@ namespace QuickMedia {
output_filepath = get_config().download.music_directory;
else
output_filepath = get_config().download.file_directory;
- output_filepath += "/" + filename;
+
+ output_filepath = get_unique_filename(output_filepath, filename);
} else {
window.set_visible(true);
output_filepath = file_save_page(filename);