Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed Oct 3, 2024
1 parent 64db911 commit a7486f4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main(int argc, argv_t* argv[]) {
int exit_code = EXIT_SUCCESS;

thread_t thread = {0};
int thread_status = 1;
int status = 1;

struct M3U8HTTPClient* client = NULL;
struct M3U8HTTPClientError* cerror = NULL;
Expand Down Expand Up @@ -152,7 +152,15 @@ int main(int argc, argv_t* argv[]) {
#endif

#if !defined(__HAIKU__)
if (is_administrator()) {
status = is_administrator();

#if defined(_WIN32)
if (status && is_wine()) {
status = 0;
}
#endif

if (status) {
err = M3U8ERR_CLI_PRIVILEGED_PROCESS_UNALLOWED;
goto end;
}
Expand Down Expand Up @@ -231,17 +239,17 @@ int main(int argc, argv_t* argv[]) {
goto end;
}

thread_status = !(options.verbose || options.disable_progress);
status = !(options.verbose || options.disable_progress);

if (thread_status) {
if (status) {
hide_cursor();
thread_create(&thread, loading_progress_callback, (void*) &thread_status);
thread_create(&thread, loading_progress_callback, (void*) &status);
}

err = m3u8stream_load(&stream, options.url, options.base_url);

if (thread_status) {
thread_status = 0;
if (status) {
status = 0;
thread_wait(&thread);
show_cursor();
}
Expand Down
31 changes: 31 additions & 0 deletions src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
#if defined(_UNICODE)
static const wchar_t WENV_APPDATA[] = L"APPDATA";
static const wchar_t WENV_PATH[] = L"PATH";

static const wchar_t WNTDLL[] = L"ntdll.dll";
#else
static const char ENV_USERPROFILE[] = "USERPROFILE";
static const char ENV_APPDATA[] = "APPDATA";
static const char ENV_PATH[] = "PATH";

static const char NTDLL[] = "ntdll.dll";
#endif
#endif

Expand Down Expand Up @@ -153,6 +157,33 @@ int execute_shell_command(const char* const command) {
}
#endif

#if defined(_WIN32)
int is_wine(void) {
/*
Returns whether the caller's process is running under Wine.
Returns (1) on true, (0) on false, (-1) on error.
*/

#if defined(_UNICODE)
HMODULE module = GetModuleHandleW(WNTDLL);
#else
HMODULE module = GetModuleHandleA(NTDLL);
#endif

if (module == NULL) {
return -1;
}

if (GetProcAddress(module, "wine_get_version") == NULL) {
return 0;
}

return 1;

}
#endif

char* get_configuration_directory(void) {
/*
Returns the config directory of the current user for applications.
Expand Down
4 changes: 4 additions & 0 deletions src/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
int is_administrator(void);
#endif

#if defined(_WIN32)
int is_wine(void);
#endif

int execute_shell_command(const char* const command);
char* get_configuration_directory(void);
char* get_temporary_directory(void);
Expand Down
4 changes: 2 additions & 2 deletions src/wio.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int wio_printf(const char* const format, ...) {
goto end;
}

value = malloc((size_t) wsize + 1);
value = malloc((size_t) (wsize + 1));

if (value == NULL) {
wsize = -1;
Expand Down Expand Up @@ -87,7 +87,7 @@ int wio_fprintf(FILE* const stream, const char* const format, ...) {
goto end;
}

value = malloc((size_t) wsize + 1);
value = malloc((size_t) (wsize + 1));

if (value == NULL) {
wsize = -1;
Expand Down

0 comments on commit a7486f4

Please sign in to comment.