Skip to content

Commit

Permalink
* exewrap 1.6.1
Browse files Browse the repository at this point in the history
実行ファイルのディレクトリーをカレントディレクトリーに設定する拡張フラグ CD_APPDIR を追加しました。
これにより、システムプロパティ― user.dir にも実行ファイルのディレクトリーが設定されるようになります。

git-svn-id: http://svn.osdn.net/svnroot/exewrap/exewrap/trunk/exewrap@89 d83a06de-854e-4732-85b7-fdf7162022b6
  • Loading branch information
hirukawa_ryo committed Jul 12, 2020
1 parent 69ddd9c commit 629add4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
3 changes: 3 additions & 0 deletions samples/gui-swing-3/SwingSample3.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public void run() {
if(text.length() > 0) {
label.setText(text.toString());
}
if((frame.getExtendedState() & JFrame.ICONIFIED) != 0) {
frame.setExtendedState(frame.getExtendedState() & ~JFrame.ICONIFIED);
}
frame.toFront();
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/image_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ int wmain(int argc, wchar_t* argv[])
exit_process(ERROR_BUSY, NULL);
}
}
if(wcsstr(ext_flags, L"CD_APPDIR") != NULL)
{
// 拡張フラグ CD_APPDIR が指定されている場合、実行ファイルのあるフォルダーをカレントディレクトリに設定します。
// これによりJavaのシステムプロパティ user.dir にも実行ファイルのあるフォルダーが設定されることになります。
wchar_t* app_dir = (wchar_t*)malloc(MAX_LONG_PATH * sizeof(wchar_t));
if(app_dir == NULL) {
exit_process(ERROR_NOT_ENOUGH_MEMORY, L"malloc");
}
GetModuleFileName(NULL, app_dir, MAX_LONG_PATH);
*(wcsrchr(app_dir, L'\\')) = L'\0';
SetCurrentDirectory(app_dir);
free(app_dir);
}
}
if(ext_flags == NULL || wcsstr(ext_flags, L"NOENCODINGFIX") == NULL)
{
Expand Down
13 changes: 13 additions & 0 deletions src/image_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t* lpCmd
goto EXIT;
}
}
if(wcsstr(ext_flags, L"CD_APPDIR") != NULL)
{
// 拡張フラグ CD_APPDIR が指定されている場合、実行ファイルのあるフォルダーをカレントディレクトリに設定します。
// これによりJavaのシステムプロパティ user.dir にも実行ファイルのあるフォルダーが設定されることになります。
wchar_t* app_dir = (wchar_t*)malloc(MAX_LONG_PATH * sizeof(wchar_t));
if(app_dir == NULL) {
exit_process(ERROR_NOT_ENOUGH_MEMORY, L"malloc");
}
GetModuleFileName(NULL, app_dir, MAX_LONG_PATH);
*(wcsrchr(app_dir, L'\\')) = L'\0';
SetCurrentDirectory(app_dir);
free(app_dir);
}
}
if(ext_flags == NULL || wcsstr(ext_flags, L"NOENCODINGFIX") == NULL)
{
Expand Down
42 changes: 20 additions & 22 deletions src/image_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static wchar_t** parse_opt(int argc, const wchar_t* argv[]);
static void write_message(WORD event_type, const wchar_t* message);
static void write_message_by_error_code(WORD evnet_type, DWORD last_error, const wchar_t* append);
static void show_help_message(void);
static void set_current_directory(void);
static wchar_t* get_service_name(void);
static wchar_t* get_pipe_name(void);
static DWORD run_as_administrator(HANDLE pipe, int argc, const wchar_t* argv[], const wchar_t* append);
Expand All @@ -64,6 +63,7 @@ static HANDLE hConOut = NULL;

int wmain(int argc, wchar_t* argv[])
{
wchar_t* ext_flags = NULL;
wchar_t* service_name = NULL;
int opt_end = 0;
wchar_t* pipe_name = NULL;
Expand All @@ -72,22 +72,34 @@ int wmain(int argc, wchar_t* argv[])

service_name = get_service_name();
flags = parse_args(&argc, argv, &opt_end);
ext_flags = from_utf8((char*)get_resource(L"EXTFLAGS", NULL));

if(flags & SHOW_HELP_MESSAGE)
{
wchar_t* ext_flags = from_utf8((char*)get_resource(L"EXTFLAGS", NULL));
if(ext_flags == NULL || wcsstr(ext_flags, L"NOHELP") == NULL)
{
show_help_message();
goto EXIT;
}
}

// プロセスがサービスとして実行されている場合、または拡張フラグ CD_APPDIR が指定されている場合、
// 実行ファイルのあるフォルダーをカレントディレクトリに設定します。
// これによりJavaのシステムプロパティ user.dir にも実行ファイルのあるフォルダーが設定されることになります。
if((flags & SERVICE_START_BY_SCM) || (ext_flags != NULL && wcsstr(ext_flags, L"CD_APPDIR") != NULL))
{
wchar_t* app_dir = (wchar_t*)malloc(MAX_LONG_PATH * sizeof(wchar_t));
if(app_dir != NULL) {
GetModuleFileName(NULL, app_dir, MAX_LONG_PATH);
*(wcsrchr(app_dir, L'\\')) = L'\0';
SetCurrentDirectory(app_dir);
free(app_dir);
}
}

if(flags & SERVICE_START_BY_SCM)
{
SERVICE_TABLE_ENTRY ServiceTable[2];

set_current_directory();

ARG_COUNT = argc;
ARG_VALUE = argv;
Expand Down Expand Up @@ -174,6 +186,10 @@ int wmain(int argc, wchar_t* argv[])
{
free(service_name);
}
if(ext_flags != NULL)
{
free(ext_flags);
}

ExitProcess(error);
}
Expand Down Expand Up @@ -1277,24 +1293,6 @@ static void show_help_message()
}


static void set_current_directory()
{
wchar_t* filepath = NULL;

filepath = (wchar_t*)malloc(MAX_LONG_PATH * sizeof(wchar_t));
if(filepath == NULL)
{
return;
}

GetModuleFileName(NULL, filepath, MAX_LONG_PATH);
*(wcsrchr(filepath, L'\\')) = L'\0';
SetCurrentDirectory(filepath);

free(filepath);
}


static wchar_t* get_service_name()
{
wchar_t* name = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/resources/exewrap.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
LANGUAGE 0,0

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,6,0,0
FILEVERSION 1,6,1,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS VS_FF_PRERELEASE
FILEOS VOS_NT_WINDOWS32
Expand All @@ -16,7 +16,7 @@ FILETYPE VFT_APP
VALUE "FileDescription", "Native executable java application wrapper.\0"
VALUE "LegalCopyright", "(C) 2005-2020 HIRUKAWA Ryo\0"
VALUE "ProductName", "exewrap\0"
VALUE "ProductVersion", "1.6.0\0"
VALUE "ProductVersion", "1.6.1\0"
VALUE "OriginalFilename", "exewrap.exe\0"
}
}
Expand Down

0 comments on commit 629add4

Please sign in to comment.