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

Merge feature/fix-config-load into main #3

Merged
merged 2 commits into from
Aug 6, 2024
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
10 changes: 8 additions & 2 deletions src-tauri/src/inihandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ pub fn read_ini_file(
.resolve_resource(path)
.expect("Failed to resolve resource");

// Get the current executable directory path
let exe_dir = env::current_dir().map_err(|e| e.to_string())?;

// Append filename w/ extension to the executable directory path
let exe_file_path = exe_dir.join(PathBuf::from(path).file_name().unwrap());

// Read the entire file content
let mut file = std::fs::File::open(resource_path).map_err(|e| e.to_string())?;
let mut file = std::fs::File::open(exe_file_path).map_err(|e| e.to_string())?;
let mut content = String::new();
file.read_to_string(&mut content)
.map_err(|e| e.to_string())?;
Expand Down Expand Up @@ -205,7 +211,7 @@ fn write_to_file(
writeln!(temp_file, "{}", line).map_err(|e| e.to_string())?;
} else if trimmed.starts_with('#') && trimmed.contains('=') && in_section {
// Remove comment so the key-value pair can be read and displayed in the UI
writeln!(temp_file, "{}", line.replace('#', "")).map_err(|e| e.to_string())?;
writeln!(temp_file, "{}", line.replace('#', "").trim()).map_err(|e| e.to_string())?;
} else if trimmed.starts_with('#') {
// Preserve comments outside of section grouping
writeln!(temp_file, "{}", line).map_err(|e| e.to_string())?;
Expand Down
7 changes: 3 additions & 4 deletions src/components/IniFileViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,18 @@

if (confirmNavigation) {
cancelEditing();
await loadIniFile(`.editordata/${newFileName}`);
await loadIniFile(`${newFileName}`);
} else {
// If the user cancels navigation, we need to revert the route change
// This assumes you're using vue-router. Adjust if you're using a different routing solution.
history.pushState(history.state, '', `#/${oldFileName}`);
await loadIniFile(`.editordata/${oldFileName}`);
await loadIniFile(`${oldFileName}`);
}
} catch (error) {
console.error("Error during navigation confirmation:", error);
// Handle the error appropriately
}
} else {
await loadIniFile(`.editordata/${newFileName}`);
await loadIniFile(`${newFileName}`);
}
}, { immediate: true });

Expand Down