Skip to content

Commit e07f05a

Browse files
committed
Merge branch 'onedrive-info' into angle-meld
2 parents aae775e + aaeea19 commit e07f05a

4 files changed

Lines changed: 139 additions & 24 deletions

File tree

.github/workflows/main.yml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,66 @@ jobs:
55
strategy:
66
matrix:
77
include:
8-
- platform: win32
8+
- platform: x64
99
os: windows-latest
10-
triplet: x86-windows
11-
# - platform: x64
12-
# os: windows-latest
13-
# triplet: x64-windows
10+
triplet: x64-windows
1411
runs-on: ${{ matrix.os }}
1512
env:
1613
VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}
1714
VCPKG_INSTALLED_DIR: ${{ github.workspace }}/vcpkg_installed/
1815
DEPS_DIR: ${{ github.workspace }}/vcpkg_installed/${{ matrix.triplet }}
16+
INST_DIR: ${{ github.workspace }}/install-prefix
1917
steps:
2018
- name: Checkout
2119
uses: actions/checkout@v2
2220
with:
2321
submodules: "recursive"
22+
2423
- name: run-vcpkg
2524
uses: lukka/run-vcpkg@v10
2625
with:
2726
vcpkgJsonGlob: "./vcpkg.json"
2827
runVcpkgInstall: true
28+
2929
- name: Setup MSBuild
3030
uses: microsoft/setup-msbuild@v1
31-
- name: Check dependencies
32-
run: "ls ${{ env.DEPS_DIR }}"
31+
32+
- name: Obtain and run CMake
33+
uses: threeal/cmake-action@v1.3.0
34+
with:
35+
source-dir: "."
36+
build-dir: "build"
37+
generator: "Visual Studio 17 2022"
38+
options: CMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake CMAKE_INSTALL_PREFIX="${{ env.INST_DIR }}"
39+
3340
- name: Build DLL
34-
run: "msbuild SimpleGraphic.vcxproj /p:configuration=release /p:platform=${{ matrix.platform }}"
41+
run: "cmake --build build --config Release -t INSTALL"
42+
3543
- name: Archive DLL
3644
uses: actions/upload-artifact@v3
3745
with:
3846
name: SimpleGraphic-${{ matrix.triplet }}.dll
39-
path: "${{ github.workspace }}/Release/SimpleGraphic.dll"
47+
path: "${{ env.INST_DIR }}/SimpleGraphic.dll"
48+
4049
- name: Archive DLL symbols
4150
uses: actions/upload-artifact@v3
4251
with:
4352
name: SimpleGraphic-${{ matrix.triplet }}.pdb
44-
path: "${{ github.workspace }}/Release/SimpleGraphic.pdb"
53+
path: "${{ github.workspace }}/build/Release/SimpleGraphic.pdb"
54+
4555
- name: Archive dependency DLLs
4656
uses: actions/upload-artifact@v3
4757
with:
4858
name: SimpleGraphic-${{ matrix.triplet }}-deps.dll
49-
path: "${{ env.DEPS_DIR }}/bin/*.dll"
59+
path: |
60+
${{ env.INST_DIR }}/*.dll
61+
!${{ env.INST_DIR }}/SimpleGraphic.dll
62+
5063
- name: Archive dependency DLL symbols
5164
uses: actions/upload-artifact@v3
5265
with:
5366
name: SimpleGraphic-${{ matrix.triplet }}-deps.pdb
54-
path: "${{ env.DEPS_DIR }}/bin/*.pdb"
67+
path: |
68+
${{ env.DEPS_DIR }}/bin/*.pdb
69+
${{ github.workspace }}/build/Release/lzip.pdb
70+
${{ github.workspace }}/build/Release/lcurl.pdb

CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
project(SimpleGraphic C CXX)
21
cmake_minimum_required(VERSION 3.15)
2+
project(SimpleGraphic C CXX)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44
set(CMAKE_CXX_STANDARD 17)
55

@@ -8,14 +8,17 @@ if (APPLE)
88
endif ()
99

1010
if (MSVC)
11-
add_compile_definitions(
12-
)
11+
add_compile_options("/Zi")
12+
add_link_options("/DEBUG")
1313
endif ()
1414

1515
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
1616

1717
include(${PROJECT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
1818

19+
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")
20+
include(InstallRequiredSystemLibraries)
21+
1922
set(SIMPLEGRAPHIC_SOURCES
2023
"config.h"
2124
"engine/common/common.cpp"
@@ -77,9 +80,9 @@ add_library(SimpleGraphic SHARED
7780
${SIMPLEGRAPHIC_SOURCES}
7881
${SIMPLEGRAPHIC_PLATFORM_SOURCES}
7982
)
80-
8183
target_compile_definitions(SimpleGraphic
8284
PRIVATE
85+
"UNICODE"
8386
"_CRT_SECURE_NO_DEPRECATE"
8487
"_CRT_SECURE_NO_WARNINGS"
8588
"_SCL_SECURE_NO_DEPRECATE"
@@ -187,8 +190,11 @@ install(FILES $<TARGET_RUNTIME_DLLS:SimpleGraphic> DESTINATION ".")
187190
install(TARGETS SimpleGraphic RUNTIME DESTINATION ".")
188191

189192
if (WIN32)
190-
find_file(LUAJIT_DLL NAMES "lua51.dll" PATHS "${CMAKE_BINARY_DIR}" REQUIRED)
191-
find_file(ZLIB_DLL NAMES "zlib1.dll" PATHS "${CMAKE_BINARY_DIR}" REQUIRED)
193+
if (DEFINED ENV{DEPS_DIR})
194+
set(DEPS_BIN_DIR ${DEPS_DIR}/bin)
195+
endif ()
196+
find_file(LUAJIT_DLL NAMES "lua51.dll" PATHS "${CMAKE_BINARY_DIR}" ${DEPS_BIN_DIR} REQUIRED)
197+
find_file(ZLIB_DLL NAMES "zlib1.dll" PATHS "${CMAKE_BINARY_DIR}" ${DEPS_BIN_DIR} REQUIRED)
192198
install(FILES ${LUAJIT_DLL} ${ZLIB_DLL} DESTINATION ".")
193199
endif ()
194200

engine/system/win/sys_main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -584,17 +584,17 @@ void sys_main_c::SpawnProcess(const char* cmdName, const char* argList)
584584
if ( !strchr(cmd, '.') ) {
585585
strcat(cmd, ".exe");
586586
}
587-
SHELLEXECUTEINFO sinfo;
588-
memset(&sinfo, 0, sizeof(SHELLEXECUTEINFO));
589-
sinfo.cbSize = sizeof(SHELLEXECUTEINFO);
587+
SHELLEXECUTEINFOA sinfo;
588+
memset(&sinfo, 0, sizeof(SHELLEXECUTEINFOA));
589+
sinfo.cbSize = sizeof(SHELLEXECUTEINFOA);
590590
sinfo.fMask = SEE_MASK_NOCLOSEPROCESS;
591591
sinfo.lpFile = cmd;
592592
sinfo.lpParameters = argList;
593593
sinfo.lpVerb = "open";
594594
sinfo.nShow = SW_SHOWMAXIMIZED;
595-
if ( !ShellExecuteEx(&sinfo) ) {
595+
if ( !ShellExecuteExA(&sinfo) ) {
596596
sinfo.lpVerb = "runas";
597-
ShellExecuteEx(&sinfo);
597+
ShellExecuteExA(&sinfo);
598598
}
599599
#else
600600
#warning LV: Subprocesses not implemented on this OS.
@@ -606,7 +606,7 @@ void sys_main_c::SpawnProcess(const char* cmdName, const char* argList)
606606
void PlatformOpenURL(const char* url)
607607
{
608608
#ifdef _WIN32
609-
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWDEFAULT);
609+
ShellExecuteA(NULL, "open", url, NULL, NULL, SW_SHOWDEFAULT);
610610
#else
611611
#warning LV: URL opening not implemented on this OS.
612612
// TODO(LV): Implement URL opening for other OSes.

ui_api.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
** fileSize = searchHandle:GetFileSize()
5353
** modified, date, time = searchHande:GetFileModifiedTime()
5454
**
55+
** provider, version, status = GetCloudProvider(path)
56+
**
5557
** SetWindowTitle("<title>")
5658
** x, y = GetCursorPos()
5759
** SetCursorPos(x, y)
@@ -646,6 +648,96 @@ static int l_searchHandleGetFileModifiedTime(lua_State* L)
646648
return 1;
647649
}
648650

651+
// ===================
652+
// Cloud provider info
653+
// ===================
654+
655+
struct CloudProviderInfo {
656+
std::string name;
657+
std::string version;
658+
uint32_t status;
659+
};
660+
661+
#ifdef _WIN32
662+
#include <Windows.h>
663+
#include <cfapi.h>
664+
665+
static std::string NarrowString(std::wstring_view ws) {
666+
auto cb = WideCharToMultiByte(CP_UTF8, 0, ws.data(), ws.size(), nullptr, 0, nullptr, nullptr);
667+
std::string ret(cb, '\0');
668+
WideCharToMultiByte(CP_UTF8, 0, ws.data(), ws.size(), ret.data(), ret.size(), nullptr, nullptr);
669+
return ret;
670+
}
671+
672+
struct CloudProviderLibrary {
673+
CloudProviderLibrary() {
674+
cldLib = LoadLibraryW(L"cldapi.dll");
675+
if (cldLib != nullptr) {
676+
CfGetSyncRootInfoByPath = (decltype (CfGetSyncRootInfoByPath))GetProcAddress(cldLib, "CfGetSyncRootInfoByPath");
677+
}
678+
}
679+
680+
~CloudProviderLibrary() {
681+
FreeLibrary(cldLib);
682+
}
683+
684+
bool Loaded() const { return cldLib != nullptr && CfGetSyncRootInfoByPath != nullptr; }
685+
686+
CloudProviderLibrary(CloudProviderLibrary const&) = delete;
687+
CloudProviderLibrary& operator = (CloudProviderLibrary const&) = delete;
688+
689+
decltype (&::CfGetSyncRootInfoByPath) CfGetSyncRootInfoByPath{};
690+
691+
HMODULE cldLib{};
692+
};
693+
694+
static std::optional<CloudProviderInfo> GetCloudProviderInfo(std::filesystem::path const& path) {
695+
HRESULT hr{ S_OK };
696+
DWORD len{};
697+
static std::vector<char> buf(65536);
698+
static CloudProviderLibrary lib;
699+
if (!lib.Loaded()) {
700+
return {};
701+
}
702+
hr = lib.CfGetSyncRootInfoByPath(path.generic_wstring().c_str(), CF_SYNC_ROOT_INFO_PROVIDER, buf.data(), buf.size(), &len);
703+
if (FAILED(hr) && GetLastError() != ERROR_MORE_DATA) {
704+
return {};
705+
}
706+
auto* syncRootInfo = (CF_SYNC_ROOT_PROVIDER_INFO const*)buf.data();
707+
buf.resize(len);
708+
hr = lib.CfGetSyncRootInfoByPath(path.c_str(), CF_SYNC_ROOT_INFO_PROVIDER, buf.data(), len, &len);
709+
if (FAILED(hr)) {
710+
return {};
711+
}
712+
CloudProviderInfo ret{};
713+
ret.name = NarrowString(syncRootInfo->ProviderName);
714+
ret.version = NarrowString(syncRootInfo->ProviderVersion);
715+
ret.status = syncRootInfo->ProviderStatus;
716+
return ret;
717+
}
718+
#else
719+
static std::optional<CloudProviderInfo> GetCloudProviderInfo(std::filesystem::path const& path) {
720+
return {};
721+
}
722+
#endif
723+
724+
static int l_GetCloudProvider(lua_State* L) {
725+
ui_main_c* ui = GetUIPtr(L);
726+
int n = lua_gettop(L);
727+
ui->LAssert(L, n >= 1, "Usage: GetCloudProvider(path)");
728+
ui->LAssert(L, lua_isstring(L, 1), "GetCloudProvider() argument 1: expected string, got %s", luaL_typename(L, 1));
729+
730+
auto info = GetCloudProviderInfo(lua_tostring(L, 1));
731+
if (info) {
732+
lua_pushstring(L, info->name.c_str());
733+
lua_pushstring(L, info->version.c_str());
734+
lua_pushinteger(L, info->status);
735+
return 3;
736+
}
737+
738+
return 0;
739+
}
740+
649741
// =================
650742
// General Functions
651743
// =================
@@ -1287,6 +1379,7 @@ int ui_main_c::InitAPI(lua_State* L)
12871379
lua_setfield(L, LUA_REGISTRYINDEX, "uisearchhandlemeta");
12881380

12891381
// General function
1382+
ADDFUNC(GetCloudProvider);
12901383
ADDFUNC(SetWindowTitle);
12911384
ADDFUNC(GetCursorPos);
12921385
ADDFUNC(SetCursorPos);

0 commit comments

Comments
 (0)