aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-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);