Skip to content

Commit f770f9a

Browse files
refactor: move database to ~/.celemod
1 parent 9e49f16 commit f770f9a

File tree

7 files changed

+140
-35
lines changed

7 files changed

+140
-35
lines changed

.github/workflows/rust.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ jobs:
119119
with:
120120
name: linux-appimage
121121
path: celemod-linux.AppImage
122-
- uses: actions/upload-artifact@v4.3.1
123-
with:
124-
name: linux-zip
125-
path: celemod-linux.zip
126122
build-macos:
127123
runs-on: macos-latest
128124
steps:

Cargo.lock

Lines changed: 68 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ strip_bom = "1.0.0"
1919
open = "*"
2020
include-bytes-zstd = "*"
2121
msgbox = "0.7.0"
22+
dirs = "*"
2223

2324
[target.'cfg(windows)'.dependencies]
2425
winapi = { version = "*", features = ["wincon", "consoleapi"] }

resources/dist.rc

-207 KB
Binary file not shown.
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
2-
3-
import * as env from '@env'
4-
import * as storage from '@storage'
5-
import * as sys from '@sys'
6-
7-
window.env = env
8-
window.storage = storage
1+
import * as env from "@env";
2+
import * as storage from "@storage";
3+
import * as sys from "@sys";
4+
window.env = env;
5+
window.storage = storage;
6+
window.sys = sys;

src/celemod-ui/src/states.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,11 @@ declare global {
3333

3434
export const useStorage = () => {
3535
if (!window.configStorage) {
36-
let path = './cele-mod.db';
37-
const exists = (path)=>{
38-
try {
39-
sys.fs.statSync(path);
40-
return true;
41-
} catch (e) {
42-
return false;
43-
}
44-
}
45-
if (exists('../../cele-mod.db')) {
46-
path = '../../cele-mod.db';
47-
}
36+
// Get database path from Rust backend (handles migration)
37+
const dbPath = callRemote("get_database_path");
4838

49-
console.log('useStorage', path)
50-
window.configStorage = storage.open(path);
39+
console.log('useStorage', dbPath)
40+
window.configStorage = storage.open(dbPath);
5141

5242
window.addEventListener('beforeunload', () => {
5343
configStorage.close();

src/main.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
path::{Path, PathBuf},
1515
rc::Rc,
1616
};
17+
use dirs;
1718

1819
extern crate msgbox;
1920

@@ -695,6 +696,65 @@ impl Handler {
695696
everest::is_using_cache()
696697
}
697698

699+
fn get_database_path(&self) -> String {
700+
use std::io::Read;
701+
702+
// Get home directory
703+
let home_dir = match dirs::home_dir() {
704+
Some(dir) => dir,
705+
None => {
706+
// Fallback to current directory
707+
return "./cele-mod.db".to_string();
708+
}
709+
};
710+
711+
let celemod_dir = home_dir.join(".celemod");
712+
let new_path = celemod_dir.join("cele-mod.db");
713+
714+
// Old paths
715+
let old_cwd_path = Path::new("./cele-mod.db").to_path_buf();
716+
let old_parent_path = Path::new("../../cele-mod.db").to_path_buf();
717+
718+
// Ensure ~/.celemod directory exists
719+
let _ = std::fs::create_dir_all(&celemod_dir);
720+
721+
// Check if old database exists and new one doesn't
722+
let old_db_path = if old_parent_path.exists() {
723+
Some(old_parent_path)
724+
} else if old_cwd_path.exists() {
725+
Some(old_cwd_path)
726+
} else {
727+
None
728+
};
729+
730+
if let Some(old_path) = old_db_path {
731+
if !new_path.exists() {
732+
// Migrate old database to new location
733+
println!("Migrating database from {:?} to {:?}", old_path, new_path);
734+
match std::fs::read(&old_path) {
735+
Ok(data) => {
736+
match std::fs::write(&new_path, &data) {
737+
Ok(_) => {
738+
let _ = std::fs::remove_file(&old_path);
739+
println!("Database migration completed");
740+
}
741+
Err(e) => {
742+
eprintln!("Failed to write new database: {}", e);
743+
return old_path.to_string_lossy().to_string();
744+
}
745+
}
746+
}
747+
Err(e) => {
748+
eprintln!("Failed to read old database: {}", e);
749+
return old_path.to_string_lossy().to_string();
750+
}
751+
}
752+
}
753+
}
754+
755+
new_path.to_string_lossy().to_string()
756+
}
757+
698758
fn sync_blacklist_profile_from_file(&self, game_path: String, profile_name: String) -> String {
699759
let result = blacklist::sync_blacklist_profile_from_file(&game_path, &profile_name);
700760
if let Err(e) = result {
@@ -926,6 +986,7 @@ impl sciter::EventHandler for Handler {
926986
fn get_current_blacklist_content(String);
927987
fn sync_blacklist_profile_from_file(String, String);
928988
fn is_using_cache();
989+
fn get_database_path();
929990
}
930991
}
931992

0 commit comments

Comments
 (0)