diff --git a/package.json b/package.json index 29bcab3..f5a0210 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fswin", - "version": "3.24.524", + "version": "3.24.829", "description": "nodejs fs extensions for windows", "main": "index.js", "types": "index.d.ts", diff --git a/readme.md b/readme.md index 5761077..31f058f 100755 --- a/readme.md +++ b/readme.md @@ -3,6 +3,51 @@ [`fswin`](https://www.npmjs.com/package/fswin) is a native [`node.js`](http://nodejs.org) add-on that works on windows. It has ported some platform specified filesystem APIs. And made them easy to use in javascript. -For details and examples please see [wiki](https://github.com/xxoo/node-fswin/wiki) +For api documents and examples please see [wiki](https://github.com/xxoo/node-fswin/wiki) NOTE: fswin depends on n-api since v3. which requires node.js v8 or later. + +## How to Install + +You may install fswin by using the following command line: + +``` +npm install fswin +``` + +The package contains prebuilt binaries for `node.js`, `electron` and `nw.js` on all architectures. + +## How to Build + +first you need to install [Visual Studio](http://www.visualstudio.com) 2019 or later. + +then you need to install [Python](https://www.python.org/downloads/windows) + +then you need to install node-gyp + +``` +npm -g install node-gyp +``` + +then you need to clone the repo + +``` +git clone https://github.com/xxoo/node-fswin.git +cd node-fswin +``` + +finally you can build the source + +for `node.js`: + +``` +node-gyp rebuild +``` + +for `electron`: + +``` +node-gyp rebuild --target=x.x.x --dist-url=https://atom.io/download/electron +``` + +for `nw.js` please follow the [official document](https://nwjs.readthedocs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/) diff --git a/src/convertPath.h b/src/convertPath.h index bc2bb93..5a919f2 100644 --- a/src/convertPath.h +++ b/src/convertPath.h @@ -3,8 +3,8 @@ class convertPath { public: - static wchar_t *func(const wchar_t *path, bool islong) {//you need to delete the result yourself if it is not NULL - wchar_t *tpath; + static wchar_t* func(const wchar_t* path, bool islong) {//you need to delete the result yourself if it is not NULL + wchar_t* tpath; DWORD sz = islong ? GetLongPathNameW(path, NULL, 0) : GetShortPathNameW(path, NULL, 0); if (sz > 0) { tpath = new wchar_t[sz]; @@ -24,9 +24,9 @@ class convertPath { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; + wchar_t* path; bool islong; - wchar_t *result; + wchar_t* result; }; static napi_value sync(napi_env env, napi_callback_info info) { napi_value result; @@ -46,14 +46,14 @@ class convertPath { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); bool islong = false; if (argc > 1) { napi_coerce_to_bool(env, argv[1], &tmp); napi_get_value_bool(env, tmp, &islong); } - wchar_t *s = func(str, islong); + wchar_t* s = func(str, islong); delete[]str; if (s) { napi_create_string_utf16(env, (char16_t*)s, wcslen(s), &result); @@ -79,7 +79,7 @@ class convertPath { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; data->islong = false; size_t str_len; napi_value tmp; @@ -114,12 +114,12 @@ class convertPath { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path, d->islong); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); diff --git a/src/dirWatcher.h b/src/dirWatcher.h index 7bea740..cd8c0c0 100644 --- a/src/dirWatcher.h +++ b/src/dirWatcher.h @@ -30,9 +30,9 @@ class dirWatcher { } private: const struct msg { - const char *type; - const wchar_t *content; - msg *next; + const char* type; + const wchar_t* content; + msg* next; }; static napi_ref constructor; @@ -46,7 +46,7 @@ class dirWatcher { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - dirWatcher *self = new dirWatcher(); + dirWatcher* self = new dirWatcher(); self->watchingParent = self->watchingPath = 0; self->pathmsg = self->parentmsg = NULL; self->oldName = self->newName = self->longName = self->shortName = NULL; @@ -136,18 +136,20 @@ class dirWatcher { } return result; } - static void Destroy(napi_env env, void *nativeObject, void *finalize_hint) { - dirWatcher *self = (dirWatcher*)nativeObject; + static void Destroy(napi_env env, void* nativeObject, void* finalize_hint) { + dirWatcher* self = (dirWatcher*)nativeObject; napi_delete_reference(env, self->wrapper); napi_delete_reference(env, self->callback); - napi_delete_async_work(env, self->pathwork); - napi_delete_async_work(env, self->parentwork); - delete[]self->path; - delete self; + if (self->watchingPath == 0 && self->pathhnd == INVALID_HANDLE_VALUE) { + delete self; + } else {//the user did not call close method before dirWatcher is garbage collected + self->callback = self->wrapper = NULL; + self->stopWatching(env); + } } static napi_value close(napi_env env, napi_callback_info info) {//this method returns false if dirWatcher is failed to create or already closed napi_value that, result; - dirWatcher *self; + dirWatcher* self; napi_get_cb_info(env, info, NULL, NULL, &that, NULL); napi_unwrap(env, that, (void**)&self); if (self->watchingPath == 0 && self->pathhnd == INVALID_HANDLE_VALUE) { @@ -158,8 +160,8 @@ class dirWatcher { } return result; } - static void beginWatchingPath(napi_env env, void *data) { - dirWatcher *self = (dirWatcher*)data; + static void beginWatchingPath(napi_env env, void* data) { + dirWatcher* self = (dirWatcher*)data; self->watchingPath = 2; if (self->pathhnd == INVALID_HANDLE_VALUE) { self->pathhnd = CreateFileW(self->path, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); @@ -181,95 +183,87 @@ class dirWatcher { } } } - static void finishWatchingPath(napi_env env, napi_status status, void *data) { - dirWatcher *self = (dirWatcher*)data; + static void finishWatchingPath(napi_env env, napi_status status, void* data) { + dirWatcher* self = (dirWatcher*)data; self->watchingPath = 0; - if (status == napi_ok) { - if (self->pathmsg) { - while (self->pathmsg) { - napi_value v; - napi_create_string_utf16(env, (char16_t*)self->pathmsg->content, NAPI_AUTO_LENGTH, &v); - self->callCb(env, self->pathmsg->type, v); - msg *m = self->pathmsg; - self->pathmsg = m->next; - delete m; - } - if (self->pathhnd == INVALID_HANDLE_VALUE) { - self->checkWatchingStoped(env); - } else { - self->watchPath(env); - } + if (status != napi_ok) { + self->checkWatchingStoped(env); + } else if (self->pathmsg) { + while (self->pathmsg) { + napi_value v; + napi_create_string_utf16(env, (char16_t*)self->pathmsg->content, NAPI_AUTO_LENGTH, &v); + self->callCb(env, self->pathmsg->type, v); + msg* m = self->pathmsg; + self->pathmsg = m->next; + delete m; + } + if (self->pathhnd == INVALID_HANDLE_VALUE) { + self->checkWatchingStoped(env); } else { - if (self->pathhnd == INVALID_HANDLE_VALUE) { - free(self->pathbuffer); - self->checkWatchingStoped(env); - } else { - if (self->watchingPathResult) { - void *buffer = self->pathbuffer; - self->watchPath(env); - FILE_NOTIFY_INFORMATION *pInfo; - DWORD d = 0; - do { - pInfo = (FILE_NOTIFY_INFORMATION*)((ULONG_PTR)buffer + d); - d += pInfo->NextEntryOffset; - napi_value filename; - napi_create_string_utf16(env, (char16_t*)pInfo->FileName, pInfo->FileNameLength / sizeof(wchar_t), &filename); - if (pInfo->Action == FILE_ACTION_ADDED) { - self->callCb(env, "ADDED", filename); - } else if (pInfo->Action == FILE_ACTION_REMOVED) { - self->callCb(env, "REMOVED", filename); - } else if (pInfo->Action == FILE_ACTION_MODIFIED) { - self->callCb(env, "MODIFIED", filename); - } else { - if (pInfo->Action == FILE_ACTION_RENAMED_OLD_NAME) { - if (self->newName) { - napi_value arg, tmp; - napi_create_object(env, &arg); - napi_set_named_property(env, arg, SYB_EVT_RENAMED_OLD_NAME, filename); - napi_create_string_utf16(env, (char16_t*)self->newName, NAPI_AUTO_LENGTH, &tmp); - napi_set_named_property(env, arg, SYB_EVT_RENAMED_NEW_NAME, tmp); - delete[]self->newName; - self->newName = NULL; - self->callCb(env, SYB_EVT_RENAMED, arg); - } else { - size_t sz = (size_t)pInfo->FileNameLength + 1; - self->oldName = new wchar_t[sz]; - wcscpy_s(self->oldName, sz, pInfo->FileName); - } - } else if (pInfo->Action == FILE_ACTION_RENAMED_NEW_NAME) { - if (self->oldName) { - napi_value arg, tmp; - napi_create_object(env, &arg); - napi_set_named_property(env, arg, SYB_EVT_RENAMED_NEW_NAME, filename); - napi_create_string_utf16(env, (char16_t*)self->oldName, NAPI_AUTO_LENGTH, &tmp); - napi_set_named_property(env, arg, SYB_EVT_RENAMED_OLD_NAME, tmp); - delete[]self->oldName; - self->oldName = NULL; - self->callCb(env, SYB_EVT_RENAMED, arg); - } else { - size_t sz = (size_t)pInfo->FileNameLength + 1; - self->newName = new wchar_t[sz]; - wcscpy_s(self->newName, sz, pInfo->FileName); - } - } - } - } while (pInfo->NextEntryOffset > 0); - free(buffer); + self->watchPath(env); + } + } else if (self->pathhnd == INVALID_HANDLE_VALUE) { + free(self->pathbuffer); + self->checkWatchingStoped(env); + } else if (self->watchingPathResult) { + void* buffer = self->pathbuffer; + self->watchPath(env); + FILE_NOTIFY_INFORMATION* pInfo; + DWORD d = 0; + do { + pInfo = (FILE_NOTIFY_INFORMATION*)((ULONG_PTR)buffer + d); + d += pInfo->NextEntryOffset; + napi_value filename; + napi_create_string_utf16(env, (char16_t*)pInfo->FileName, pInfo->FileNameLength / sizeof(wchar_t), &filename); + if (pInfo->Action == FILE_ACTION_ADDED) { + self->callCb(env, "ADDED", filename); + } else if (pInfo->Action == FILE_ACTION_REMOVED) { + self->callCb(env, "REMOVED", filename); + } else if (pInfo->Action == FILE_ACTION_MODIFIED) { + self->callCb(env, "MODIFIED", filename); + } else if (pInfo->Action == FILE_ACTION_RENAMED_OLD_NAME) { + if (self->newName) { + napi_value arg, tmp; + napi_create_object(env, &arg); + napi_set_named_property(env, arg, SYB_EVT_RENAMED_OLD_NAME, filename); + napi_create_string_utf16(env, (char16_t*)self->newName, NAPI_AUTO_LENGTH, &tmp); + napi_set_named_property(env, arg, SYB_EVT_RENAMED_NEW_NAME, tmp); + delete[]self->newName; + self->newName = NULL; + self->callCb(env, SYB_EVT_RENAMED, arg); } else { - free(self->pathbuffer); - napi_value v; - napi_create_string_utf16(env, (char16_t*)SYB_EVT_ERR_UNABLE_TO_CONTINUE_WATCHING, NAPI_AUTO_LENGTH, &v); - self->callCb(env, SYB_EVT_ERR, v); - self->stopWatching(env); + size_t sz = (size_t)pInfo->FileNameLength + 1; + self->oldName = new wchar_t[sz]; + wcscpy_s(self->oldName, sz, pInfo->FileName); + } + } else if (pInfo->Action == FILE_ACTION_RENAMED_NEW_NAME) { + if (self->oldName) { + napi_value arg, tmp; + napi_create_object(env, &arg); + napi_set_named_property(env, arg, SYB_EVT_RENAMED_NEW_NAME, filename); + napi_create_string_utf16(env, (char16_t*)self->oldName, NAPI_AUTO_LENGTH, &tmp); + napi_set_named_property(env, arg, SYB_EVT_RENAMED_OLD_NAME, tmp); + delete[]self->oldName; + self->oldName = NULL; + self->callCb(env, SYB_EVT_RENAMED, arg); + } else { + size_t sz = (size_t)pInfo->FileNameLength + 1; + self->newName = new wchar_t[sz]; + wcscpy_s(self->newName, sz, pInfo->FileName); } } - } + } while (pInfo->NextEntryOffset > 0); + free(buffer); } else { - self->checkWatchingStoped(env); + free(self->pathbuffer); + napi_value v; + napi_create_string_utf16(env, (char16_t*)SYB_EVT_ERR_UNABLE_TO_CONTINUE_WATCHING, NAPI_AUTO_LENGTH, &v); + self->callCb(env, SYB_EVT_ERR, v); + self->stopWatching(env); } } - static void beginWatchingParent(napi_env env, void *data) { - dirWatcher *self = (dirWatcher*)data; + static void beginWatchingParent(napi_env env, void* data) { + dirWatcher* self = (dirWatcher*)data; self->watchingParent = 2; if (self->parenthnd == INVALID_HANDLE_VALUE) { self->savePath(env); @@ -278,56 +272,50 @@ class dirWatcher { self->watchingParentResult = ReadDirectoryChangesW(self->parenthnd, self->parentbuffer, SYB_BUFFERSIZE, FALSE, FILE_NOTIFY_CHANGE_DIR_NAME, &d, NULL, NULL); } } - static void finishWatchingParent(napi_env env, napi_status status, void *data) { - dirWatcher *self = (dirWatcher*)data; + static void finishWatchingParent(napi_env env, napi_status status, void* data) { + dirWatcher* self = (dirWatcher*)data; self->watchingParent = 0; - if (status == napi_ok) { - if (self->parentmsg) { - while (self->parentmsg) { - napi_value v; - napi_create_string_utf16(env, (char16_t*)self->parentmsg->content, NAPI_AUTO_LENGTH, &v); - self->callCb(env, self->parentmsg->type, v); - msg *m = self->parentmsg; - self->parentmsg = m->next; - delete m; - } - if (self->parenthnd == INVALID_HANDLE_VALUE) { - self->checkWatchingStoped(env); - } else { - self->watchParent(env); - } + if (status != napi_ok) { + self->checkWatchingStoped(env); + } else if (self->parentmsg) { + while (self->parentmsg) { + napi_value v; + napi_create_string_utf16(env, (char16_t*)self->parentmsg->content, NAPI_AUTO_LENGTH, &v); + self->callCb(env, self->parentmsg->type, v); + msg* m = self->parentmsg; + self->parentmsg = m->next; + delete m; + } + if (self->parenthnd == INVALID_HANDLE_VALUE) { + self->checkWatchingStoped(env); } else { - if (self->parenthnd == INVALID_HANDLE_VALUE) { - self->checkWatchingStoped(env); - } else { - if (self->watchingParentResult) { - FILE_NOTIFY_INFORMATION *pInfo; - DWORD d = 0; - do { - pInfo = (FILE_NOTIFY_INFORMATION*)((ULONG_PTR)self->parentbuffer + d); - d += pInfo->NextEntryOffset; - if ((pInfo->Action == FILE_ACTION_RENAMED_OLD_NAME || pInfo->Action == FILE_ACTION_REMOVED) && wcsncmp(self->longName, pInfo->FileName, MAX(pInfo->FileNameLength / sizeof(wchar_t), wcslen(self->longName))) == 0 || (self->shortName && wcsncmp(self->shortName, pInfo->FileName, MAX(pInfo->FileNameLength / sizeof(wchar_t), wcslen(self->shortName))) == 0)) { - CloseHandle(self->parenthnd); - self->parenthnd = INVALID_HANDLE_VALUE; - break; - } - } while (pInfo->NextEntryOffset > 0); - self->watchParent(env); - } else { - napi_value v; - napi_create_string_utf16(env, (char16_t*)SYB_EVT_ERR_UNABLE_TO_WATCH_SELF, NAPI_AUTO_LENGTH, &v); - self->callCb(env, SYB_EVT_ERR, v); - self->stopWatchingParent(env); - } - } + self->watchParent(env); } - } else { + } else if (self->parenthnd == INVALID_HANDLE_VALUE) { self->checkWatchingStoped(env); + } else if (self->watchingParentResult) { + FILE_NOTIFY_INFORMATION* pInfo; + DWORD d = 0; + do { + pInfo = (FILE_NOTIFY_INFORMATION*)((ULONG_PTR)self->parentbuffer + d); + d += pInfo->NextEntryOffset; + if ((pInfo->Action == FILE_ACTION_RENAMED_OLD_NAME || pInfo->Action == FILE_ACTION_REMOVED) && wcsncmp(self->longName, pInfo->FileName, MAX(pInfo->FileNameLength / sizeof(wchar_t), wcslen(self->longName))) == 0 || (self->shortName && wcsncmp(self->shortName, pInfo->FileName, MAX(pInfo->FileNameLength / sizeof(wchar_t), wcslen(self->shortName))) == 0)) { + CloseHandle(self->parenthnd); + self->parenthnd = INVALID_HANDLE_VALUE; + break; + } + } while (pInfo->NextEntryOffset > 0); + self->watchParent(env); + } else { + napi_value v; + napi_create_string_utf16(env, (char16_t*)SYB_EVT_ERR_UNABLE_TO_WATCH_SELF, NAPI_AUTO_LENGTH, &v); + self->callCb(env, SYB_EVT_ERR, v); + self->stopWatchingParent(env); } } - msg *pathmsg; - msg *parentmsg; + msg* pathmsg; + msg* parentmsg; HANDLE pathhnd; HANDLE parenthnd; napi_async_work pathwork; @@ -338,13 +326,13 @@ class dirWatcher { BYTE watchingParent; bool subDirs; DWORD options; - wchar_t *path; - wchar_t *oldName; - wchar_t *newName; - wchar_t *shortName; - wchar_t *longName; - void *pathbuffer; - BYTE *parentbuffer[SYB_BUFFERSIZE]; + wchar_t* path; + wchar_t* oldName; + wchar_t* newName; + wchar_t* shortName; + wchar_t* longName; + void* pathbuffer; + BYTE* parentbuffer[SYB_BUFFERSIZE]; napi_ref wrapper; napi_ref callback; @@ -369,12 +357,12 @@ class dirWatcher { } } void savePath(napi_env env, bool starting = false) { - wchar_t *realPath = getCurrentPathByHandle(this->pathhnd); + wchar_t* realPath = getCurrentPathByHandle(this->pathhnd); bool e = false; if (realPath) { delete[]this->path; this->path = realPath; - splitPath::splitedPath *sp = splitPath::func(this->path); + splitPath::splitedPath* sp = splitPath::func(this->path); if (sp->parentLen > 0) { if (this->shortName) { delete[]this->shortName; @@ -384,7 +372,7 @@ class dirWatcher { delete[]this->longName; this->longName = NULL; } - find::resultData *fr = find::func(this->path); + find::resultData* fr = find::func(this->path); if (fr) { size_t l = wcslen(fr->data.cFileName) + 1; this->longName = new wchar_t[l]; @@ -398,9 +386,9 @@ class dirWatcher { } if (this->longName) { size_t l = (size_t)sp->parentLen + 1; - wchar_t *parent = new wchar_t[l]; + wchar_t* parent = new wchar_t[l]; wcsncpy_s(parent, l, realPath, sp->parentLen); - this->parenthnd = CreateFileW(parent, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + this->parenthnd = CreateFileW(parent, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); delete[]parent; if (this->parenthnd == INVALID_HANDLE_VALUE) { e = true; @@ -419,7 +407,7 @@ class dirWatcher { } else { e = true; } - msg *m = new msg; + msg* m = new msg; m->content = this->path; if (starting) { m->type = "STARTED"; @@ -459,7 +447,7 @@ class dirWatcher { } void stopWatchingParent(napi_env env) { if (this->parenthnd != INVALID_HANDLE_VALUE) { - CloseHandle(this->parenthnd); + BOOL res = CloseHandle(this->parenthnd); this->parenthnd = INVALID_HANDLE_VALUE; } if (this->longName) { @@ -479,15 +467,23 @@ class dirWatcher { napi_value v; napi_get_undefined(env, &v); this->callCb(env, "ENDED", v); + napi_delete_async_work(env, this->pathwork); + napi_delete_async_work(env, this->parentwork); + delete[]this->path; + if (!this->wrapper) { + delete this; + } } } - void callCb(napi_env env, const char *evt_type, napi_value content) { - napi_value argv[2], func, that; - napi_create_string_latin1(env, evt_type, NAPI_AUTO_LENGTH, &argv[0]); - argv[1] = content; - napi_get_reference_value(env, this->callback, &func); - napi_get_reference_value(env, this->wrapper, &that); - napi_call_function(env, that, func, 2, &argv[0], NULL); + void callCb(napi_env env, const char* evt_type, napi_value content) { + if (this->callback && this->wrapper) { + napi_value argv[2], func, that; + napi_create_string_latin1(env, evt_type, NAPI_AUTO_LENGTH, &argv[0]); + argv[1] = content; + napi_get_reference_value(env, this->callback, &func); + napi_get_reference_value(env, this->wrapper, &that); + napi_call_function(env, that, func, 2, &argv[0], NULL); + } } }; napi_ref dirWatcher::constructor; \ No newline at end of file diff --git a/src/ejectDrive.h b/src/ejectDrive.h index d9464e9..e37b836 100644 --- a/src/ejectDrive.h +++ b/src/ejectDrive.h @@ -106,7 +106,7 @@ class ejectDrive { napi_valuetype t; napi_typeof(env, argv[2], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_coerce_to_number(env, argv[1], &tmp); @@ -141,12 +141,12 @@ class ejectDrive { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->l, d->method); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); napi_get_reference_value(env, d->self, &self); diff --git a/src/find.h b/src/find.h index 855ed26..f9c266e 100644 --- a/src/find.h +++ b/src/find.h @@ -5,12 +5,12 @@ class find { public: const struct resultData {//this is a linked table WIN32_FIND_DATAW data; - resultData *next; + resultData* next; }; //progressive callback type, if this callback returns true, the search will stop immediately. the contents of info will be rewritten or released after the callback returns, so make a copy before starting a new thread if you still need to use it - typedef bool(*findResultCall)(const WIN32_FIND_DATAW *info, void *data); - static resultData *func(const wchar_t *path) {//you have to delete every linked data yourself if it is not NULL - resultData *result = new resultData; + typedef bool(*findResultCall)(const WIN32_FIND_DATAW* info, void* data); + static resultData* func(const wchar_t* path) {//you have to delete every linked data yourself if it is not NULL + resultData* result = new resultData; CHAR bak; if (RtlSetThreadPlaceholderCompatibilityMode) { bak = RtlSetThreadPlaceholderCompatibilityMode(2); @@ -20,7 +20,7 @@ class find { delete result; result = NULL; } else { - resultData *resultnew, *resultold; + resultData* resultnew,* resultold; if (isValidInfo(&result->data)) { resultnew = new resultData; resultold = result; @@ -53,7 +53,7 @@ class find { } return result; } - static DWORD funcWithCallback(const wchar_t *path, const findResultCall callback, void *data) {//data could be anything that will directly pass to the callback + static DWORD funcWithCallback(const wchar_t* path, const findResultCall callback, void* data) {//data could be anything that will directly pass to the callback WIN32_FIND_DATAW info; CHAR bak; if (RtlSetThreadPlaceholderCompatibilityMode) { @@ -95,7 +95,7 @@ class find { napi_async_work work; napi_ref self; napi_ref cb; - void *data; + void* data; //the following data is only used in progressive mode HANDLE hnd; size_t count; @@ -119,7 +119,7 @@ class find { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); if (argc > 1) { napi_valuetype t; @@ -154,7 +154,7 @@ class find { napi_typeof(env, argv[1], &t); if (t == napi_function) { bool isProgressive = false; - asyncCbData *data = new asyncCbData; + asyncCbData* data = new asyncCbData; size_t str_len; napi_value tmp; napi_coerce_to_string(env, argv[0], &tmp); @@ -195,10 +195,10 @@ class find { } return result; } - static bool isValidInfo(const WIN32_FIND_DATAW *info) {//determine whether it is the real content + static bool isValidInfo(const WIN32_FIND_DATAW* info) {//determine whether it is the real content return wcscmp(info->cFileName, L".") != 0 && wcscmp(info->cFileName, L"..") != 0; } - static napi_value resultDataToArray(napi_env env, resultData *r) { + static napi_value resultDataToArray(napi_env env, resultData* r) { napi_value result; napi_create_array(env, &result); if (r) { @@ -208,14 +208,14 @@ class find { while (r) { tmp = convert(env, &r->data); napi_call_function(env, result, push, 1, &tmp, NULL); - resultData *n = r->next; + resultData* n = r->next; delete r; r = n; } } return result; } - static napi_value convert(napi_env env, const WIN32_FIND_DATAW *info) { + static napi_value convert(napi_env env, const WIN32_FIND_DATAW* info) { napi_value result, tmp, date; napi_create_object(env, &result); napi_get_global(env, &date); @@ -381,19 +381,19 @@ class find { napi_set_named_property(env, result, "REPARSE_POINT_TAG", tmp); return result; } - static bool syncCallback(const WIN32_FIND_DATAW *info, void *data) { + static bool syncCallback(const WIN32_FIND_DATAW* info, void* data) { bool result; - syncCbData *d = (syncCbData*)data; + syncCbData* d = (syncCbData*)data; napi_value res, o = convert(d->env, info); napi_call_function(d->env, d->self, d->cb, 1, &o, &res); napi_coerce_to_bool(d->env, res, &res); napi_get_value_bool(d->env, res, &result); return result; } - static void execute(napi_env env, void *data) { - asyncCbData *d = (asyncCbData*)data; + static void execute(napi_env env, void* data) { + asyncCbData* d = (asyncCbData*)data; if (d->hnd) { - WIN32_FIND_DATAW *info = new WIN32_FIND_DATAW; + WIN32_FIND_DATAW* info = new WIN32_FIND_DATAW; if (d->hnd == INVALID_HANDLE_VALUE) { CHAR bak; if ((void*)RtlSetThreadPlaceholderCompatibilityMode) { @@ -445,13 +445,13 @@ class find { d->data = info; } } else { - resultData *rdata = func((wchar_t*)d->data); + resultData* rdata = func((wchar_t*)d->data); delete[]d->data; d->data = rdata; } } - static void complete(napi_env env, napi_status status, void *data) { - asyncCbData *d = (asyncCbData*)data; + static void complete(napi_env env, napi_status status, void* data) { + asyncCbData* d = (asyncCbData*)data; napi_value cb, self; napi_get_reference_value(env, d->cb, &cb); napi_get_reference_value(env, d->self, &self); diff --git a/src/fsWin.cpp b/src/fsWin.cpp index 451a600..cf82ba9 100644 --- a/src/fsWin.cpp +++ b/src/fsWin.cpp @@ -19,7 +19,7 @@ NAPI_MODULE_INIT() { napi_value o; - napi_create_string_latin1(env, "3.23.119", NAPI_AUTO_LENGTH, &o); + napi_create_string_latin1(env, "3.24.829", NAPI_AUTO_LENGTH, &o); napi_set_named_property(env, exports, "version", o); napi_set_named_property(env, exports, "dirWatcher", dirWatcher::init(env)); napi_set_named_property(env, exports, "splitPath", splitPath::init(env)); diff --git a/src/getAttributes.h b/src/getAttributes.h index 43e6e57..49baf96 100644 --- a/src/getAttributes.h +++ b/src/getAttributes.h @@ -13,8 +13,8 @@ class getAttributes { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; - BY_HANDLE_FILE_INFORMATION *result; + wchar_t* path; + BY_HANDLE_FILE_INFORMATION* result; }; static napi_value sync(napi_env env, napi_callback_info info) { napi_value result; @@ -34,7 +34,7 @@ class getAttributes { napi_coerce_to_string(env, argv, &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); BY_HANDLE_FILE_INFORMATION data; CHAR bak; @@ -72,7 +72,7 @@ class getAttributes { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_create_reference(env, argv[1], 1, &data->cb); @@ -102,7 +102,7 @@ class getAttributes { } return result; } - static napi_value convert(napi_env env, BY_HANDLE_FILE_INFORMATION *info) { + static napi_value convert(napi_env env, BY_HANDLE_FILE_INFORMATION* info) { napi_value result, tmp, date; napi_get_global(env, &date); napi_get_named_property(env, date, "Date", &date); @@ -166,8 +166,8 @@ class getAttributes { napi_set_named_property(env, result, "IS_REPARSE_POINT", tmp); return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = new BY_HANDLE_FILE_INFORMATION; CHAR bak; if (RtlSetThreadPlaceholderCompatibilityMode) { @@ -185,8 +185,8 @@ class getAttributes { RtlSetThreadPlaceholderCompatibilityMode(bak); } } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); diff --git a/src/getCompressedSize.h b/src/getCompressedSize.h index 5dc4695..4c9e52a 100644 --- a/src/getCompressedSize.h +++ b/src/getCompressedSize.h @@ -3,7 +3,7 @@ class getCompressedSize { public: - static ULONGLONG func(const wchar_t *path) { + static ULONGLONG func(const wchar_t* path) { ULARGE_INTEGER u; u.LowPart = GetCompressedFileSizeW(path, &u.HighPart); if (u.LowPart == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) { @@ -21,7 +21,7 @@ class getCompressedSize { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; + wchar_t* path; ULONGLONG result; }; static napi_value sync(napi_env env, napi_callback_info info) { @@ -42,7 +42,7 @@ class getCompressedSize { napi_coerce_to_string(env, argv, &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); napi_create_int64(env, func(str), &result); delete[]str; @@ -64,7 +64,7 @@ class getCompressedSize { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_create_reference(env, argv[1], 1, &data->cb); @@ -94,13 +94,13 @@ class getCompressedSize { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path); delete[]d->path; } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); napi_get_reference_value(env, d->self, &self); diff --git a/src/getDeviceCapabilities.h b/src/getDeviceCapabilities.h index a5e7c88..fe20b8f 100644 --- a/src/getDeviceCapabilities.h +++ b/src/getDeviceCapabilities.h @@ -121,12 +121,12 @@ class getDeviceCapabilities { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->DevInstId); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; napi_value cb, self, argv = convert(env, d->result); napi_get_reference_value(env, d->cb, &cb); napi_get_reference_value(env, d->self, &self); diff --git a/src/getDriveDevice.h b/src/getDriveDevice.h index f2a07bb..c9adf97 100644 --- a/src/getDriveDevice.h +++ b/src/getDriveDevice.h @@ -187,7 +187,7 @@ class getDriveDevice { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_coerce_to_string(env, argv[0], &tmp); @@ -218,12 +218,12 @@ class getDriveDevice { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->l); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); napi_get_reference_value(env, d->self, &self); diff --git a/src/getLogicalDriveList.h b/src/getLogicalDriveList.h index c4078fe..fe473ad 100644 --- a/src/getLogicalDriveList.h +++ b/src/getLogicalDriveList.h @@ -77,7 +77,7 @@ class getLogicalDriveList { napi_valuetype t; napi_typeof(env, argv, &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; napi_value tmp; napi_create_reference(env, argv, 1, &data->cb); napi_create_reference(env, self, 1, &data->self); @@ -129,12 +129,12 @@ class getLogicalDriveList { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); napi_get_reference_value(env, d->self, &self); diff --git a/src/getVolumeInformation.h b/src/getVolumeInformation.h index d6e9d5c..79f6e14 100644 --- a/src/getVolumeInformation.h +++ b/src/getVolumeInformation.h @@ -10,8 +10,8 @@ class getVolumeInformation { DWORD maximumComponentLength; DWORD fileSystemFlags; }; - static infor *func(const wchar_t *path) {//you need to delete the result yourself if it is not NULL - infor *result = new infor; + static infor* func(const wchar_t* path) {//you need to delete the result yourself if it is not NULL + infor* result = new infor; if (!GetVolumeInformationW(path, result->label, MAX_PATH + 1, &result->serialNumber, &result->maximumComponentLength, &result->fileSystemFlags, result->fileSystem, MAX_PATH + 1)) { delete result; result = NULL; @@ -28,8 +28,8 @@ class getVolumeInformation { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; - infor *result; + wchar_t* path; + infor* result; }; static napi_value sync(napi_env env, napi_callback_info info) { napi_value result; @@ -49,9 +49,9 @@ class getVolumeInformation { napi_coerce_to_string(env, argv, &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); - infor *r = func(str); + infor* r = func(str); delete[]str; if (r) { result = convert(env, r); @@ -77,7 +77,7 @@ class getVolumeInformation { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_create_reference(env, argv[1], 1, &data->cb); @@ -107,7 +107,7 @@ class getVolumeInformation { } return result; } - static napi_value convert(napi_env env, infor *data) { + static napi_value convert(napi_env env, infor* data) { napi_value tmp, result; napi_create_object(env, &result); napi_create_string_utf16(env, (char16_t*)data->label, NAPI_AUTO_LENGTH, &tmp); @@ -177,12 +177,12 @@ class getVolumeInformation { return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); diff --git a/src/getVolumeSpace.h b/src/getVolumeSpace.h index 70a21e5..f219f1d 100644 --- a/src/getVolumeSpace.h +++ b/src/getVolumeSpace.h @@ -7,10 +7,10 @@ class getVolumeSpace { ULONGLONG totalSpace; ULONGLONG freeSpace; }; - static spaces *func(const wchar_t *path) {//you need to delete the result yourself if it is not NULL + static spaces* func(const wchar_t* path) {//you need to delete the result yourself if it is not NULL ULARGE_INTEGER u1; ULARGE_INTEGER u2; - spaces *result; + spaces* result; if (GetDiskFreeSpaceExW(path, &u1, &u2, NULL)) { result = new spaces; result->freeSpace = u1.QuadPart; @@ -30,8 +30,8 @@ class getVolumeSpace { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; - spaces *result; + wchar_t* path; + spaces* result; }; static napi_value sync(napi_env env, napi_callback_info info) { napi_value result; @@ -51,9 +51,9 @@ class getVolumeSpace { napi_coerce_to_string(env, argv, &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); - spaces *r = func(str); + spaces* r = func(str); delete[]str; if (r) { result = convert(env, r); @@ -79,7 +79,7 @@ class getVolumeSpace { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_create_reference(env, argv[1], 1, &data->cb); @@ -109,7 +109,7 @@ class getVolumeSpace { } return result; } - static napi_value convert(napi_env env, spaces *data) { + static napi_value convert(napi_env env, spaces* data) { napi_value tmp, result; napi_create_object(env, &result); napi_create_int64(env, data->freeSpace, &tmp); @@ -118,12 +118,12 @@ class getVolumeSpace { napi_set_named_property(env, result, "TOTAL", tmp); return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); diff --git a/src/setAttributes.h b/src/setAttributes.h index 53a2864..d9e2361 100644 --- a/src/setAttributes.h +++ b/src/setAttributes.h @@ -14,7 +14,7 @@ class setAttributes { char unpinned; char pinned; }; - static bool func(const wchar_t *file, const attrVal *attr) { + static bool func(const wchar_t* file, const attrVal* attr) { bool result; DWORD oldattr = GetFileAttributesW(file); if (oldattr == INVALID_FILE_ATTRIBUTES) { @@ -84,8 +84,8 @@ class setAttributes { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; - attrVal *attr; + wchar_t* path; + attrVal* attr; bool result; }; static napi_value sync(napi_env env, napi_callback_info info) { @@ -107,9 +107,9 @@ class setAttributes { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); - attrVal *attr = convert(env, argv[1]); + attrVal* attr = convert(env, argv[1]); napi_get_boolean(env, func(str, attr), &result); delete attr; delete[]str; @@ -136,7 +136,7 @@ class setAttributes { napi_typeof(env, argv[1], &t1); napi_typeof(env, argv[2], &t); if (t1 == napi_object && t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; data->attr = convert(env, argv[1]); @@ -167,8 +167,8 @@ class setAttributes { } return result; } - static attrVal *convert(napi_env env, napi_value attr) {//delete the result yourself - attrVal *result = new attrVal; + static attrVal* convert(napi_env env, napi_value attr) {//delete the result yourself + attrVal* result = new attrVal; bool tmp; napi_value val; napi_has_named_property(env, attr, SYB_FILEATTR_ISARCHIVED, &tmp); @@ -245,12 +245,12 @@ class setAttributes { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path, d->attr); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; delete d->attr; napi_value cb, self, argv; diff --git a/src/setCompression.h b/src/setCompression.h index 92d2042..3e094cc 100644 --- a/src/setCompression.h +++ b/src/setCompression.h @@ -3,7 +3,7 @@ class setCompression { public: - static bool func(const wchar_t *path, const bool compress, const bool create) { + static bool func(const wchar_t* path, const bool compress, const bool create) { bool result = false; HANDLE hnd = CreateFileW(path, FILE_GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, create ? OPEN_ALWAYS : OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hnd != INVALID_HANDLE_VALUE) { @@ -26,7 +26,7 @@ class setCompression { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; + wchar_t* path; bool compress; bool create; bool result; @@ -49,7 +49,7 @@ class setCompression { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *path = new wchar_t[str_len]; + wchar_t* path = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)path, str_len, NULL); bool compress = false, create = false; if (argc > 1) { @@ -80,7 +80,7 @@ class setCompression { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; data->compress = data->create = false; size_t str_len; napi_value tmp; @@ -119,12 +119,12 @@ class setCompression { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path, d->compress, d->create); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); diff --git a/src/setShortName.h b/src/setShortName.h index deb4161..c7bec8d 100644 --- a/src/setShortName.h +++ b/src/setShortName.h @@ -3,7 +3,7 @@ class setShortName { public: - static bool func(const wchar_t *path, const wchar_t *newname) { + static bool func(const wchar_t* path, const wchar_t* newname) { bool result; if (ensurePrivilege("SeRestorePrivilege")) {//make sure the process has SE_RESTORE_NAME privilege HANDLE hnd = CreateFileW(path, GENERIC_WRITE | DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); @@ -28,8 +28,8 @@ class setShortName { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; - wchar_t *newname; + wchar_t* path; + wchar_t* newname; bool result; }; static napi_value sync(napi_env env, napi_callback_info info) { @@ -50,12 +50,12 @@ class setShortName { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *path = new wchar_t[str_len]; + wchar_t* path = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)path, str_len, NULL); napi_coerce_to_string(env, argv[1], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *newname = new wchar_t[str_len]; + wchar_t* newname = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)path, str_len, NULL); napi_get_boolean(env, func(path, newname), &result); delete[]path; @@ -78,7 +78,7 @@ class setShortName { napi_valuetype t; napi_typeof(env, argv[2], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_create_reference(env, argv[2], 1, &data->cb); @@ -114,12 +114,12 @@ class setShortName { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path, d->newname); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; delete[]d->newname; napi_value cb, self, argv; diff --git a/src/setSparse.h b/src/setSparse.h index 4e63844..144b7e1 100644 --- a/src/setSparse.h +++ b/src/setSparse.h @@ -3,7 +3,7 @@ class setSparse { public: - static bool func(const wchar_t *path, const bool create) { + static bool func(const wchar_t* path, const bool create) { bool result = false; HANDLE hnd = CreateFileW(path, FILE_GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, create ? OPEN_ALWAYS : OPEN_EXISTING, 0, NULL); if (hnd != INVALID_HANDLE_VALUE) { @@ -25,7 +25,7 @@ class setSparse { napi_async_work work; napi_ref self; napi_ref cb; - wchar_t *path; + wchar_t* path; bool create; bool result; }; @@ -47,7 +47,7 @@ class setSparse { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *path = new wchar_t[str_len]; + wchar_t* path = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)path, str_len, NULL); bool create = false; if (argc > 1) { @@ -74,7 +74,7 @@ class setSparse { napi_valuetype t; napi_typeof(env, argv[1], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; data->create = false; size_t str_len; napi_value tmp; @@ -109,12 +109,12 @@ class setSparse { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = func(d->path, d->create); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; napi_value cb, self, argv; napi_get_reference_value(env, d->cb, &cb); diff --git a/src/setVolumeLabel.h b/src/setVolumeLabel.h index 9d0df92..e5b3f09 100644 --- a/src/setVolumeLabel.h +++ b/src/setVolumeLabel.h @@ -35,7 +35,7 @@ class setVolumeLabel { napi_coerce_to_string(env, argv[0], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *path = new wchar_t[str_len]; + wchar_t* path = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)path, str_len, NULL); napi_coerce_to_string(env, argv[1], &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); @@ -63,7 +63,7 @@ class setVolumeLabel { napi_valuetype t; napi_typeof(env, argv[2], &t); if (t == napi_function) { - cbdata *data = new cbdata; + cbdata* data = new cbdata; size_t str_len; napi_value tmp; napi_create_reference(env, argv[2], 1, &data->cb); @@ -99,12 +99,12 @@ class setVolumeLabel { } return result; } - static void execute(napi_env env, void *data) { - cbdata *d = (cbdata*)data; + static void execute(napi_env env, void* data) { + cbdata* d = (cbdata*)data; d->result = SetVolumeLabelW(d->path, d->label); } - static void complete(napi_env env, napi_status status, void *data) { - cbdata *d = (cbdata*)data; + static void complete(napi_env env, napi_status status, void* data) { + cbdata* d = (cbdata*)data; delete[]d->path; delete[]d->label; napi_value cb, self, argv; diff --git a/src/splitPath.h b/src/splitPath.h index 387ba6b..849a983 100644 --- a/src/splitPath.h +++ b/src/splitPath.h @@ -5,10 +5,10 @@ class splitPath { public: const struct splitedPath { DWORD parentLen;//the length of the parent - const wchar_t *name;//this could also be considered as the start position of the name + const wchar_t* name;//this could also be considered as the start position of the name }; - static splitedPath *func(const wchar_t *path) {//you need to delete the return value your self - const wchar_t *s = L"\\\\", s1 = L'\\'; + static splitedPath* func(const wchar_t* path) {//you need to delete the return value your self + const wchar_t* s = L"\\\\", s1 = L'\\'; DWORD i, j = 0, k = 0, l = (DWORD)wcslen(path), m = (DWORD)wcslen(s); if (wcsncmp(s, path, m) == 0) {//is network path for (i = m + 1; i < l - 1; i++) { @@ -44,7 +44,7 @@ class splitPath { } } } - splitedPath *r = new splitedPath; + splitedPath* r = new splitedPath; r->parentLen = j; r->name = &path[j > 0 ? j + k : j]; return r; @@ -73,9 +73,9 @@ class splitPath { napi_coerce_to_string(env, argv, &tmp); napi_get_value_string_utf16(env, tmp, NULL, 0, &str_len); str_len += 1; - wchar_t *str = new wchar_t[str_len]; + wchar_t* str = new wchar_t[str_len]; napi_get_value_string_utf16(env, tmp, (char16_t*)str, str_len, NULL); - splitedPath *s = func(str); + splitedPath* s = func(str); napi_create_object(env, &result); napi_create_string_utf16(env, (char16_t*)str, s->parentLen, &tmp); napi_set_named_property(env, result, "PARENT", tmp);