Skip to content

Commit

Permalink
Make Launcher Support Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Mar 22, 2024
1 parent 59eea8f commit 567d8dd
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 40 deletions.
19 changes: 19 additions & 0 deletions Tool/EffekseerLauncher/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
AccessModifierOffset: -4
UseTab: Always
BreakBeforeBraces: Allman
ColumnLimit: 0

DerivePointerAlignment: false
PointerAlignment: Left

BinPackArguments: false
BinPackParameters: false

AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortBlocksOnASingleLine: false
BreakConstructorInitializersBeforeComma : true
10 changes: 9 additions & 1 deletion Tool/EffekseerLauncher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ project(EffekseerLauncher C CXX)

set(CMAKE_CXX_STANDARD 14)

add_executable(EffekseerLauncher src/main.cpp)
if(APPLE)
add_executable(EffekseerLauncher src/main.cpp)
elseif(WIN32)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:WINDOWS")

add_executable(EffekseerLauncher WIN32 src/main.cpp resources.rc)
endif()
Binary file added Tool/EffekseerLauncher/icon.ico
Binary file not shown.
Binary file added Tool/EffekseerLauncher/resources.aps
Binary file not shown.
1 change: 1 addition & 0 deletions Tool/EffekseerLauncher/resources.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "icon.ico"
126 changes: 87 additions & 39 deletions Tool/EffekseerLauncher/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,113 @@
#include <mach-o/dyld.h>
#endif

std::string GetDirectoryName(const std::string &path) {
const std::string::size_type pos =
std::max<int32_t>(path.find_last_of('/'), path.find_last_of('\\'));
return (pos == std::string::npos) ? std::string() : path.substr(0, pos + 1);
std::string GetDirectoryName(const std::string& path)
{
const std::string::size_type pos =
std::max<int32_t>(path.find_last_of('/'), path.find_last_of('\\'));
return (pos == std::string::npos) ? std::string() : path.substr(0, pos + 1);
}

std::string GetExecutingDirectory() {
char buf[260];
std::string GetExecutingDirectory()
{
char buf[260];

#ifdef _WIN32
int len = GetModuleFileNameA(nullptr, buf, 260);
if (len <= 0)
return "";
int len = GetModuleFileNameA(nullptr, buf, 260);
if (len <= 0)
return "";
#elif defined(__APPLE__)
uint32_t size = 260;
if (_NSGetExecutablePath(buf, &size) != 0) {
buf[0] = 0;
}
uint32_t size = 260;
if (_NSGetExecutablePath(buf, &size) != 0)
{
buf[0] = 0;
}
#else

char temp[32];
sprintf(temp, "/proc/%d/exe", getpid());
int bytes = std::min((int)readlink(temp, buf, 260), 260 - 1);
if (bytes >= 0)
buf[bytes] = '\0';
char temp[32];
sprintf(temp, "/proc/%d/exe", getpid());
int bytes = std::min((int)readlink(temp, buf, 260), 260 - 1);
if (bytes >= 0)
buf[bytes] = '\0';
#endif

return GetDirectoryName(buf);
return GetDirectoryName(buf);
}

void SetCurrentDir(const char *path) {
void SetCurrentDir(const char* path)
{
#ifdef _WIN32
_chdir(path);
_chdir(path);
#else
chdir(path);
chdir(path);
#endif
}

int main(int argc, char *argv[]) {
FILE* Popen(const char* path, const char* mode)
{
#ifdef _WIN32
return _popen(path, mode);
#else
return popen(path, mode);
#endif
}

void Pclose(FILE* file)
{
#ifdef _WIN32
_pclose(file);
#else
pclose(file);
#endif
}

int mainLoop(int argc, char* argv[])
{
SetCurrentDir(GetExecutingDirectory().c_str());

SetCurrentDir(GetExecutingDirectory().c_str());
std::string cmd;

const auto cmd = "../Resources/Effekseer";
auto fp = popen(cmd, "r");
if (fp == nullptr) {
std::cout << "Failed to call " << cmd << std::endl;
return 1;
}
#ifdef _WIN32
cmd = ".\\bin\\Effekseer.exe";
#else
cmd = "../Resources/Effekseer";
#endif

for (int i = 1; i < argc; i++)
{
cmd = cmd + " \"" + argv[i] + "\"";
}

auto fp = Popen(cmd.c_str(), "r");
if (fp == nullptr)
{
std::cout << "Failed to call " << cmd << std::endl;
return 1;
}

std::array<char, 256> buffer;
std::array<char, 256> buffer;

while (!feof(fp)) {
fgets(buffer.data(), buffer.size(), fp);
std::cout << buffer.data();
}
while (!feof(fp))
{
fgets(buffer.data(), buffer.size(), fp);
std::cout << buffer.data();
}

pclose(fp);
Pclose(fp);

std::cout << "Finished " << cmd << std::endl;
std::cout << "Finished " << cmd << std::endl;

return 0;
}
return 0;
}

#if defined(_WIN32)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nShowCmd)
{
return mainLoop(__argc, __argv);
}
#else
int main(int argc, char* argv[])
{
return mainLoop(argc, argv);
}
#endif

0 comments on commit 567d8dd

Please sign in to comment.