no longer emulate FAM, due to a stupid design flaw. instead, implement sysdep/dir_watch interface
This was SVN commit r866.
This commit is contained in:
parent
09f47d6820
commit
7618033b3a
@ -4,11 +4,7 @@
|
|||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#include "sysdep/dir_watch.h"
|
||||||
#include "sysdep/win/wfam.h"
|
|
||||||
#else
|
|
||||||
#include <fam.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -18,49 +14,17 @@ int res_reload(const char* const fn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static FAMConnection fc;
|
|
||||||
static bool initialized=false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// path: portable and relative, must add current directory and convert to native
|
// path: portable and relative, must add current directory and convert to native
|
||||||
// better to use a cached string from rel_chdir - secure
|
// better to use a cached string from rel_chdir - secure
|
||||||
int res_watch_dir(const char* const path, intptr_t* const watch)
|
int res_watch_dir(const char* const path, intptr_t* const watch)
|
||||||
{
|
{
|
||||||
if(!initialized)
|
return dir_add_watch(path, watch);
|
||||||
{
|
|
||||||
CHECK_ERR(FAMOpen2(&fc, "lib_res"));
|
|
||||||
atexit2((void*)FAMClose, (uintptr_t)&fc);
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
char n_full_path[PATH_MAX];
|
|
||||||
CHECK_ERR(file_make_native_path(path, n_full_path));
|
|
||||||
|
|
||||||
FAMRequest req;
|
|
||||||
if(FAMMonitorDirectory(&fc, n_full_path, &req, (void*)0) < 0)
|
|
||||||
{
|
|
||||||
*watch = -1;
|
|
||||||
debug_warn("res_watch_dir failed!");
|
|
||||||
return -1; // no way of getting error code?
|
|
||||||
}
|
|
||||||
|
|
||||||
*watch = (intptr_t)req.reqnum;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int res_cancel_watch(const intptr_t watch)
|
int res_cancel_watch(const intptr_t watch)
|
||||||
{
|
{
|
||||||
if(!initialized)
|
return dir_cancel_watch(watch);
|
||||||
{
|
|
||||||
debug_warn("res_cancel_watch before res_watch_dir");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
FAMRequest req;
|
|
||||||
req.reqnum = (int)watch;
|
|
||||||
return FAMCancelMonitor(&fc, &req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,21 +33,13 @@ int res_cancel_watch(const intptr_t watch)
|
|||||||
// to take place here, we don't require everything to be thread-safe.
|
// to take place here, we don't require everything to be thread-safe.
|
||||||
int res_reload_changed_files()
|
int res_reload_changed_files()
|
||||||
{
|
{
|
||||||
if(!initialized)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
static double last_time;
|
static double last_time;
|
||||||
static char last_fn[VFS_MAX_PATH];
|
static char last_fn[VFS_MAX_PATH];
|
||||||
|
|
||||||
FAMEvent e;
|
char path[PATH_MAX];
|
||||||
while(FAMPending(&fc) > 0)
|
while(dir_get_changed_file(path) == 0)
|
||||||
{
|
{
|
||||||
if(FAMNextEvent(&fc, &e) < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
char path[PATH_MAX];
|
|
||||||
char vfs_path[VFS_MAX_PATH];
|
char vfs_path[VFS_MAX_PATH];
|
||||||
CHECK_ERR(file_make_portable_path(e.filename, path));
|
|
||||||
CHECK_ERR(vfs_make_vfs_path(path, vfs_path));
|
CHECK_ERR(vfs_make_vfs_path(path, vfs_path));
|
||||||
|
|
||||||
const char* fn = vfs_path;
|
const char* fn = vfs_path;
|
||||||
@ -96,7 +52,7 @@ int res_reload_changed_files()
|
|||||||
if(ext && !strcmp(ext, ".tmp"))
|
if(ext && !strcmp(ext, ".tmp"))
|
||||||
continue;
|
continue;
|
||||||
// .. and directory change (more info is upcoming anyway)
|
// .. and directory change (more info is upcoming anyway)
|
||||||
if(!ext && e.code == FAMChanged) // dir changed
|
if(!ext) // dir changed
|
||||||
continue;
|
continue;
|
||||||
// .. and reloads for the same file within a small timeframe.
|
// .. and reloads for the same file within a small timeframe.
|
||||||
double cur_time = get_time();
|
double cur_time = get_time();
|
||||||
|
Loading…
Reference in New Issue
Block a user