Move image cache to cache from config dir (#197)
This commit is contained in:
parent
7992ba30de
commit
80bbc9ba85
|
@ -645,21 +645,21 @@ fn get_string_from_similarity(similarity: &Similarity) -> &str {
|
||||||
|
|
||||||
fn save_hashes_to_file(hashmap: &HashMap<String, FileEntry>, text_messages: &mut Messages) {
|
fn save_hashes_to_file(hashmap: &HashMap<String, FileEntry>, text_messages: &mut Messages) {
|
||||||
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
||||||
// Lin: /home/alice/.config/barapp
|
// Lin: /home/username/.cache/czkawka
|
||||||
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
|
// Win: C:\Users\Username\AppData\Local\Qarmin\Czkawka\cache
|
||||||
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
|
// Mac: /Users/Username/Library/Caches/pl.Qarmin.Czkawka
|
||||||
|
|
||||||
let config_dir = PathBuf::from(proj_dirs.config_dir());
|
let cache_dir = PathBuf::from(proj_dirs.cache_dir());
|
||||||
if config_dir.exists() {
|
if cache_dir.exists() {
|
||||||
if !config_dir.is_dir() {
|
if !cache_dir.is_dir() {
|
||||||
text_messages.messages.push(format!("Config dir {} is a file!", config_dir.display()));
|
text_messages.messages.push(format!("Config dir {} is a file!", cache_dir.display()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if fs::create_dir_all(&config_dir).is_err() {
|
} else if fs::create_dir_all(&cache_dir).is_err() {
|
||||||
text_messages.messages.push(format!("Cannot create config dir {}", config_dir.display()));
|
text_messages.messages.push(format!("Cannot create config dir {}", cache_dir.display()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let config_file = config_dir.join(CACHE_FILE_NAME);
|
let config_file = cache_dir.join(CACHE_FILE_NAME);
|
||||||
let file_handler = match OpenOptions::new().truncate(true).write(true).create(true).open(&config_file) {
|
let file_handler = match OpenOptions::new().truncate(true).write(true).create(true).open(&config_file) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -688,13 +688,26 @@ fn save_hashes_to_file(hashmap: &HashMap<String, FileEntry>, text_messages: &mut
|
||||||
}
|
}
|
||||||
fn load_hashes_from_file(text_messages: &mut Messages) -> Option<HashMap<String, FileEntry>> {
|
fn load_hashes_from_file(text_messages: &mut Messages) -> Option<HashMap<String, FileEntry>> {
|
||||||
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
||||||
let config_dir = PathBuf::from(proj_dirs.config_dir());
|
let mut cache_dir = PathBuf::from(proj_dirs.cache_dir());
|
||||||
let config_file = config_dir.join(CACHE_FILE_NAME);
|
let mut config_file = cache_dir.join(CACHE_FILE_NAME);
|
||||||
let file_handler = match OpenOptions::new().read(true).open(&config_file) {
|
let file_handler = match OpenOptions::new().read(true).open(&config_file) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
text_messages.messages.push(format!("Cannot find or open cache file {}", config_file.display()));
|
text_messages.messages.push(format!("Cannot find or open cache file {}", config_file.display()));
|
||||||
return None;
|
// return None; // Enable when removing compatibility section
|
||||||
|
// Compatibility for upgrading project from 2.1 to 2.2
|
||||||
|
{
|
||||||
|
cache_dir = PathBuf::from(proj_dirs.config_dir());
|
||||||
|
config_file = cache_dir.join(CACHE_FILE_NAME);
|
||||||
|
match OpenOptions::new().read(true).open(&config_file) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err(_) => {
|
||||||
|
text_messages.messages.push(format!("Cannot find or open cache file {}", config_file.display()));
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End of compatibility section to remove after release 2.2 version
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
||||||
// Lin: /home/alice/.config/barapp
|
// Lin: /home/username/.config/czkawka
|
||||||
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
|
// Win: C:\Users\Username\AppData\Roaming\Qarmin\Czkawka\config
|
||||||
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
|
// Mac: /Users/Username/Library/Application Support/pl.Qarmin.Czkawka
|
||||||
|
|
||||||
let config_dir = proj_dirs.config_dir();
|
let config_dir = proj_dirs.config_dir();
|
||||||
if config_dir.exists() {
|
if config_dir.exists() {
|
||||||
|
@ -166,9 +166,9 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
|
||||||
reset_text_view(&text_view_errors);
|
reset_text_view(&text_view_errors);
|
||||||
|
|
||||||
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
|
||||||
// Lin: /home/alice/.config/barapp
|
// Lin: /home/username/.config/czkawka
|
||||||
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
|
// Win: C:\Users\Username\AppData\Roaming\Qarmin\Czkawka\config
|
||||||
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
|
// Mac: /Users/Username/Library/Application Support/pl.Qarmin.Czkawka
|
||||||
|
|
||||||
let config_dir = proj_dirs.config_dir();
|
let config_dir = proj_dirs.config_dir();
|
||||||
let config_file = config_dir.join(Path::new(SAVE_FILE_NAME));
|
let config_file = config_dir.join(Path::new(SAVE_FILE_NAME));
|
||||||
|
|
|
@ -130,12 +130,17 @@ For now Czkawka store only 2 files on disk:
|
||||||
- `cache_similar_image.txt` - stores cache data and hashes which may be used later without needing to compute image hash again - DO NOT TRY TO EDIT THIS FILE MANUALLY! - editing this file may cause app crashes.
|
- `cache_similar_image.txt` - stores cache data and hashes which may be used later without needing to compute image hash again - DO NOT TRY TO EDIT THIS FILE MANUALLY! - editing this file may cause app crashes.
|
||||||
|
|
||||||
|
|
||||||
This files are located in this path
|
First file is located in this path
|
||||||
|
|
||||||
Linux - `/home/username/.config/czkawka`
|
Linux - `/home/username/.config/czkawka`
|
||||||
Mac - `/Users/username/Library/Application Support/pl.Qarmin.Czkawka`
|
Mac - `/Users/username/Library/Application Support/pl.Qarmin.Czkawka`
|
||||||
Windows - `C:\Users\Alice\AppData\Roaming\Qarmin\Czkawka\config`
|
Windows - `C:\Users\Username\AppData\Roaming\Qarmin\Czkawka\config`
|
||||||
|
|
||||||
|
Second with cache here:
|
||||||
|
|
||||||
|
Linux - `/home/username/.cache/czkawka`
|
||||||
|
Mac - `/Users/Username/Library/Caches/pl.Qarmin.Czkawka`
|
||||||
|
Windows - `C:\Users\Username\AppData\Local\Qarmin\Czkawka\cache`
|
||||||
|
|
||||||
## GUI GTK
|
## GUI GTK
|
||||||
<img src="https://user-images.githubusercontent.com/41945903/103002387-14d1b800-452f-11eb-967e-9d5905dd6db5.png" width="800" />
|
<img src="https://user-images.githubusercontent.com/41945903/103002387-14d1b800-452f-11eb-967e-9d5905dd6db5.png" width="800" />
|
||||||
|
|
Loading…
Reference in a new issue