Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
Good work has been done here!
  • Loading branch information
falfiya committed May 19, 2021
1 parent b6ea201 commit c58d309
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 51 deletions.
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ cli:
gui: dist/index.js
$(npx)\qode $<

dist/index.js:
dist: webpack.config.js $(wildcard src/*.js) $(wildcard misc/*)
$(npx)\webpack

build: clean dist/index.js
deploy: dist
$(npx)\nodegui-packer --init $(name)
$(npx)\nodegui-packer --pack dist

build: clean deploy
move $(build) $@
$(rcedit) $@/qode.exe --set-icon misc/icon.ico

f: build/$(name).exe
./$<
build/$(name).exe: src/stub.c build
clang $< -Ofast -fuse-ld=lld -o $@

build/$(name).exe: src/stub.c
clang $< -Ofast -o $@
release: build build/$(name).exe
$(rcedit) $</qode.exe --set-icon misc/icon.ico
$(rcedit) $</$(name).exe --set-icon misc/icon.ico

clean:
-rd /s /q dist deploy build

.PHONY: cli gui dist/index.js build bundle deploy
.PHONY: cli gui
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@coalpha/fs_date_archivist",
"author": "coalpha",
"version": "0.2.0",
"version": "1.0.0",
"main": "src/cli.js",
"dependencies": {
"@nodegui/nodegui": "^0.30.2"
Expand Down
11 changes: 4 additions & 7 deletions src/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const {
QMessageBox,
} = require("@nodegui/nodegui");

if (process.env.SETCWD) {
process.chdir(process.env.SETCWD);
}

const win = new QMainWindow;
const win_width = 900;
const win_height = 685;
Expand Down Expand Up @@ -208,10 +212,3 @@ go_button.addEventListener("clicked", () => {

win.show();
global.win = win;

for (const arg of process.argv) {
console.log(arg);
const qlwi = new QListWidgetItem;
qlwi.setText(arg);
depth1_list.addItem(qlwi);
}
56 changes: 21 additions & 35 deletions src/stub.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include <wchar.h>
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <windows.h>

#define qode "qode.exe"
#define true 1
#define SETCWDTO "SETCWDTO"
#define SETCWD "SETCWD="
#define LEN(s) (sizeof(s) - 1)

STARTUPINFOW si;

#define LEN(s) (sizeof(s) - 1)

int wmain(int argc, wchar_t *argv[]) {
DWORD name_len = 0;
wchar_t *name = *argv;
Expand All @@ -36,11 +33,11 @@ int wmain(int argc, wchar_t *argv[]) {
// includes null byte
DWORD cwd_len = GetCurrentDirectoryW(0, NULL);

// the memory layout is going to look like `${__dirname}\0${qode} ${cwd}`
// the memory layout is going to look like `${__dirname}\0SETCWD=${cwd}\0\0`
wchar_t *dirname = _alloca(
sizeof(wchar_t) * (0
+ last_backslash + LEN("\0")
+ qode_len + LEN(" ") + LEN(SETCWDTO) + LEN(" ") + cwd_len
+ LEN("SETCWD=") + cwd_len + LEN("\0")
)
);

Expand All @@ -49,38 +46,27 @@ int wmain(int argc, wchar_t *argv[]) {
}
dirname[last_backslash] = '\0';

wchar_t *qode_arg = dirname + last_backslash + 1;
for (size_t i = 0; i < qode_len; ++i) {
qode_arg[i] = name[i];
wchar_t *env = dirname + last_backslash + 1;
for (size_t i = 0; i < LEN(SETCWD); ++i) {
env[i] = SETCWD[i];
}

wchar_t *cwd_arg = qode_arg + qode_len;
*cwd_arg++ = ' ';

for (size_t i = 0; i < LEN(SETCWDTO); ++i) {
*cwd_arg++ = SETCWDTO[i];
}

GetCurrentDirectoryW(cwd_len, cwd_arg);

wprintf(L"qode: %s\ndirname: %s\nargs: %s\n", name, dirname, qode_arg);
wchar_t *cwd = env + LEN(SETCWD);
GetCurrentDirectoryW(cwd_len, cwd);
cwd[cwd_len] = '\0';

PROCESS_INFORMATION pi;

BOOL success = CreateProcessW(
name, // lpApplicationName
qode_arg, // lpCommandLine
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
true, // bInheritHandles
0, // dwCreationFlags
NULL, // lpEnvironment
dirname, // lpCurrentDirectory
&si, // lpStartupInfo
&pi // lpProcessInformation
CreateProcessW(
name, // lpApplicationName
NULL, // lpCommandLine
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
true, // bInheritHandles
CREATE_UNICODE_ENVIRONMENT, // dwCreationFlags
env, // lpEnvironment
dirname, // lpCurrentDirectory
&si, // lpStartupInfo
&pi // lpProcessInformation
);

{
printf("Error: %lu\n", GetLastError());
}
}

0 comments on commit c58d309

Please sign in to comment.