Skip to content

Commit

Permalink
os, feat: implememt os.homedir() on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot authored and xicilion committed May 29, 2017
1 parent 9196a75 commit 955f6e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
8 changes: 4 additions & 4 deletions fibjs/fibjs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -652,7 +652,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -677,7 +677,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -704,7 +704,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand Down
8 changes: 4 additions & 4 deletions fibjs/fibjs_gui.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -652,7 +652,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -677,7 +677,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -704,7 +704,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand Down
21 changes: 21 additions & 0 deletions fibjs/src/os/os_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "utf8.h"
#include "inetAddr.h"
#include "BufferedStream.h"
#include "userenv.h"

typedef struct
_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
Expand Down Expand Up @@ -679,6 +680,26 @@ result_t os_base::homedir(exlib::string& retVal)

// process.env.HOME does not exist , call GetUserProfileDirectoryW()
if (retVal.empty()) {
HANDLE token;
exlib::wchar path[MAX_PATH];
DWORD buffersize;
int r;

if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token) == 0) {
return CHECK_ERROR(GetLastError());
}
buffersize = sizeof(path);
if (!GetUserProfileDirectoryW(token, path, &buffersize)) {
r = GetLastError();
CloseHandle(token);
if (r != ERROR_INSUFFICIENT_BUFFER)
return CHECK_ERROR(Runtime::setError("GetUserProfileDirectoryW call returned unexpectedly"));
}

CloseHandle(token);

buffersize = sizeof(path);
retVal = utf16to8String(path, (int32_t)buffersize);
}
path_base::normalize(retVal, retVal);

Expand Down
8 changes: 4 additions & 4 deletions fibjs/tools/proj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -215,7 +215,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -240,7 +240,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand All @@ -267,7 +267,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winmm.lib;ws2_32.lib;psapi.lib;dbghelp.lib;shlwapi.lib;urlmon.lib;userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
Expand Down

0 comments on commit 955f6e9

Please sign in to comment.