windows support
This commit is contained in:
parent
f1cd631aae
commit
b9004acd79
16 changed files with 208 additions and 32 deletions
|
|
@ -1,30 +1,46 @@
|
|||
#include <MDE/Core/Directory.h>
|
||||
#include <MDE/Core/String.h>
|
||||
|
||||
#include <Mw/Milsko.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
void MDEDirectoryScan(const char* path, void (*call)(const char* name, int dir, int symlink, void* user), void* user) {
|
||||
DIR* dir = opendir(path);
|
||||
void* dir = MwDirectoryOpen(path);
|
||||
if(dir != NULL) {
|
||||
struct dirent* d;
|
||||
while((d = readdir(dir)) != NULL) {
|
||||
MwDirectoryEntry* d;
|
||||
while((d = MwDirectoryRead(dir)) != NULL) {
|
||||
char* p;
|
||||
struct stat s;
|
||||
if(strcmp(d->d_name, "..") == 0 || strcmp(d->d_name, ".") == 0) continue;
|
||||
if(strcmp(d->name, "..") == 0 || strcmp(d->name, ".") == 0) continue;
|
||||
|
||||
p = malloc(strlen(path) + 1 + strlen(d->d_name) + 1);
|
||||
p = malloc(strlen(path) + 1 + strlen(d->name) + 1);
|
||||
strcpy(p, path);
|
||||
#ifdef _WIN32
|
||||
if(path[strlen(path) - 1] != '\\') strcat(p, "\\");
|
||||
#else
|
||||
if(path[strlen(path) - 1] != '/') strcat(p, "/");
|
||||
strcat(p, d->d_name);
|
||||
#endif
|
||||
strcat(p, d->name);
|
||||
|
||||
#ifdef _WIN32
|
||||
if(stat(p, &s) == 0) {
|
||||
call(p, d->type == MwDIRECTORY_DIRECTORY ? 1 : 0, 0, user);
|
||||
}
|
||||
#else
|
||||
if(lstat(p, &s) == 0) {
|
||||
call(p, S_ISDIR(s.st_mode) ? 1 : 0, S_ISLNK(s.st_mode) ? 1 : 0, user);
|
||||
}
|
||||
#endif
|
||||
|
||||
free(p);
|
||||
}
|
||||
closedir(dir);
|
||||
MwDirectoryClose(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,8 +53,13 @@ void MDEDirectoryCreate(const char* path, int mode) {
|
|||
b[0] = path[i];
|
||||
b[1] = 0;
|
||||
strcat(r, b);
|
||||
#ifdef _WIN32
|
||||
if(path[i] == '\\' || path[i] == 0) {
|
||||
mkdir(r);
|
||||
#else
|
||||
if(path[i] == '/' || path[i] == 0) {
|
||||
mkdir(r, mode);
|
||||
#endif
|
||||
if(path[i] == 0) break;
|
||||
}
|
||||
}
|
||||
|
|
@ -51,3 +72,26 @@ char* MDEDirectoryCurrentPath(void) {
|
|||
|
||||
return MDEStringDuplicate(p);
|
||||
}
|
||||
|
||||
char* MDEDirectoryConfigPath(void) {
|
||||
#ifdef _WIN32
|
||||
char* shp = malloc(MAX_PATH);
|
||||
LPITEMIDLIST pidl;
|
||||
if(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl) == S_OK) {
|
||||
SHGetPathFromIDList(pidl, shp);
|
||||
CoTaskMemFree(pidl);
|
||||
return shp;
|
||||
}
|
||||
free(shp);
|
||||
|
||||
shp = getenv("USERPROFILE");
|
||||
return shp == NULL ? NULL : MDEStringDuplicate(shp);
|
||||
#else
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
char* p = malloc(strlen(pwd->pw_dir) + strlen("/.config") + 1);
|
||||
strcpy(p, pwd->pw_dir);
|
||||
strcat(p, "/.config");
|
||||
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
12
core/file.c
12
core/file.c
|
|
@ -2,6 +2,10 @@
|
|||
#include <MDE/Core/String.h>
|
||||
#include <MDE/Core/Directory.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void MDEFileCopy(const char* src, const char* dst) {
|
||||
char buffer[4096];
|
||||
FILE* in;
|
||||
|
|
@ -65,6 +69,13 @@ char* MDEFileOptimizeAbsolutePath(const char* path) {
|
|||
}
|
||||
|
||||
char* MDEFileAbsolutePath(const char* path) {
|
||||
#ifdef _WIN32
|
||||
char* r = malloc(MAX_PATH);
|
||||
|
||||
GetFullPathName(path, MAX_PATH, r, NULL);
|
||||
|
||||
return r;
|
||||
#else
|
||||
char* p;
|
||||
char* r;
|
||||
|
||||
|
|
@ -83,4 +94,5 @@ char* MDEFileAbsolutePath(const char* path) {
|
|||
free(p);
|
||||
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
22
core/mutex.c
Normal file
22
core/mutex.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <MDE/Core/Mutex.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
MDEMutex MDEMutexCreate(void) {
|
||||
return CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||
}
|
||||
|
||||
void MDEMutexDestroy(MDEMutex mutex) {
|
||||
CloseHandle(mutex);
|
||||
}
|
||||
|
||||
void MDEMutexLock(MDEMutex mutex) {
|
||||
WaitForSingleObject(mutex, INFINITE);
|
||||
}
|
||||
|
||||
void MDEMutexUnlock(MDEMutex mutex) {
|
||||
SetEvent(mutex);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
34
core/thread.c
Normal file
34
core/thread.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <MDE/Core/Thread.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
static DWORD WINAPI call_wrapper(LPVOID param) {
|
||||
void** p = param;
|
||||
void (*call)(void* user_data) = p[0];
|
||||
void* ud = p[1];
|
||||
free(p);
|
||||
|
||||
call(ud);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MDEThread MDEThreadCreate(void (*call)(void* user_data), void* user_data) {
|
||||
void** p = malloc(sizeof(*p) * 2);
|
||||
|
||||
p[0] = call;
|
||||
p[1] = user_data;
|
||||
|
||||
return CreateThread(NULL, 0, call_wrapper, (void*)p, 0, NULL);
|
||||
}
|
||||
|
||||
void MDEThreadDestroy(MDEThread thread) {
|
||||
CloseHandle(thread);
|
||||
}
|
||||
|
||||
void MDEThreadJoin(MDEThread thread) {
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
|
|
@ -1,6 +1,12 @@
|
|||
#include <MDE/Core/Users.h>
|
||||
#include <MDE/Core/String.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
void MDEUsersList(void (*call)(const char* name, void* user), void* user) {
|
||||
/* wow */
|
||||
call("Administrator", user);
|
||||
}
|
||||
#else
|
||||
#include <pwd.h>
|
||||
|
||||
void MDEUsersList(void (*call)(const char* name, void* user), void* user) {
|
||||
|
|
@ -37,3 +43,4 @@ void MDEUsersList(void (*call)(const char* name, void* user), void* user) {
|
|||
}
|
||||
endpwent();
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue