Skip to content

Commit

Permalink
Merge pull request #3 from mcarigs/feature/fix-config-load
Browse files Browse the repository at this point in the history
Merge feature/fix-config-load into main
  • Loading branch information
mcarigs authored Aug 6, 2024
2 parents e89a46e + c449096 commit 17358e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit 17358e1

Please sign in to comment.