Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move image cache to cache from config dir #197

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions czkawka_core/src/similar_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
// Lin: /home/alice/.config/barapp
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App

let config_dir = PathBuf::from(proj_dirs.config_dir());
if config_dir.exists() {
if !config_dir.is_dir() {
text_messages.messages.push(format!("Config dir {} is a file!", config_dir.display()));
// Lin: /home/username/.cache/czkawka
// Win: C:\Users\Username\AppData\Local\Qarmin\Czkawka\cache
// Mac: /Users/Username/Library/Caches/pl.Qarmin.Czkawka

let cache_dir = PathBuf::from(proj_dirs.cache_dir());
if cache_dir.exists() {
if !cache_dir.is_dir() {
text_messages.messages.push(format!("Config dir {} is a file!", cache_dir.display()));
return;
}
} else if fs::create_dir_all(&config_dir).is_err() {
text_messages.messages.push(format!("Cannot create config dir {}", config_dir.display()));
} else if fs::create_dir_all(&cache_dir).is_err() {
text_messages.messages.push(format!("Cannot create config dir {}", cache_dir.display()));
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) {
Ok(t) => t,
Err(_) => {
Expand Down Expand Up @@ -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>> {
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
let config_dir = PathBuf::from(proj_dirs.config_dir());
let config_file = config_dir.join(CACHE_FILE_NAME);
let mut cache_dir = PathBuf::from(proj_dirs.cache_dir());
let mut config_file = cache_dir.join(CACHE_FILE_NAME);
let file_handler = 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;
// 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
}
};

Expand Down
12 changes: 6 additions & 6 deletions czkawka_gui/src/saving_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
return;
}
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
// Lin: /home/alice/.config/barapp
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
// Lin: /home/username/.config/czkawka
// Win: C:\Users\Username\AppData\Roaming\Qarmin\Czkawka\config
// Mac: /Users/Username/Library/Application Support/pl.Qarmin.Czkawka

let config_dir = proj_dirs.config_dir();
if config_dir.exists() {
Expand Down Expand Up @@ -166,9 +166,9 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
reset_text_view(&text_view_errors);

if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
// Lin: /home/alice/.config/barapp
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
// Lin: /home/username/.config/czkawka
// Win: C:\Users\Username\AppData\Roaming\Qarmin\Czkawka\config
// Mac: /Users/Username/Library/Application Support/pl.Qarmin.Czkawka

let config_dir = proj_dirs.config_dir();
let config_file = config_dir.join(Path::new(SAVE_FILE_NAME));
Expand Down
9 changes: 7 additions & 2 deletions instructions/Instruction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


This files are located in this path
First file is located in this path

Linux - `/home/username/.config/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
<img src="https://user-images.githubusercontent.com/41945903/103002387-14d1b800-452f-11eb-967e-9d5905dd6db5.png" width="800" />
Expand Down