diff --git a/source/lib/res/res.cpp b/source/lib/res/res.cpp index 5dc3bcbb07..6941663794 100755 --- a/source/lib/res/res.cpp +++ b/source/lib/res/res.cpp @@ -1,6 +1,7 @@ #include "precompiled.h" #include "res.h" +#include "file.h" #ifdef _WIN32 #include "sysdep/win/wfam.h" @@ -19,7 +20,10 @@ static FAMConnection fc; static bool initialized; -int res_mount(const char* const mount_point, const char* const name, const uint pri) + +// path: portable and relative, must add current directory and convert to native +// better to use a cached string from rel_chdir - secure +int res_watch_dir(const char* const path, uint* const reqnum) { if(!initialized) { @@ -28,21 +32,35 @@ int res_mount(const char* const mount_point, const char* const name, const uint initialized = true; } - CHECK_ERR(vfs_mount(mount_point, name, pri)); + char n_full_path[PATH_MAX]; + CHECK_ERR(file_make_native_path(path, n_full_path)); - // if is directory - // get full path - // convert to native - - static FAMRequest req; - FAMMonitorDirectory(&fc, "d:\\projects\\0ad\\cvs\\binaries\\data\\mods\\official\\", &req, 0); -//FAMCancelMonitor(&fc, &req); - // add request somewhere - have to be able to cancel watch + FAMRequest req; + if(FAMMonitorDirectory(&fc, n_full_path, &req, (void*)0) < 0) + return -1; // no way of getting error? + *reqnum = req.reqnum; return 0; } +int res_cancel_watch(const uint reqnum) +{ + if(!initialized) + { + debug_warn("res_cancel_watch before res_watch_dir"); + return -1; + } + + FAMRequest req; + req.reqnum = reqnum; + return FAMCancelMonitor(&fc, &req); +} + + +// purpose of this routine (intended to be called once a frame): +// file notification may come at any time. by forcing the reloads +// to take place here, we don't require everything to be thread-safe. int res_reload_changed_files() { if(!initialized) @@ -52,13 +70,12 @@ int res_reload_changed_files() while(FAMPending(&fc) > 0) if(FAMNextEvent(&fc, &e) == 0) { - const char* sys_fn = e.filename; + char path[PATH_MAX]; + char vfs_path[VFS_MAX_PATH]; + CHECK_ERR(file_make_portable_path(e.filename, path)); + CHECK_ERR(vfs_get_path(path, vfs_path)); + res_reload(vfs_path); } return 0; } - - -// purpose of this routine (intended to be called once a frame): -// file notification may come at any time. by forcing the reloads -// to take place here, we don't require everything to be thread-safe. diff --git a/source/lib/res/res.h b/source/lib/res/res.h index 304dd74d08..f0400c7310 100755 --- a/source/lib/res/res.h +++ b/source/lib/res/res.h @@ -11,6 +11,9 @@ extern int res_reload(const char* fn); // the following functions must be called from the same thread! // (wfam limitation) -extern int res_mount(const char* mount_point, const char* name, uint pri); + +extern int res_watch_dir(const char* const path, uint* const reqnum); + +extern int res_cancel_watch(const uint reqnum); extern int res_reload_changed_files(); \ No newline at end of file