Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion native/intuitives_daw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ elseif(PLATFORM_LINUX)
endif()
target_link_libraries(IntuitivesDAW PRIVATE m pthread dl)
elseif(PLATFORM_WINDOWS)
target_link_libraries(IntuitivesDAW PRIVATE ole32 winmm ws2_32)
target_link_libraries(IntuitivesDAW PRIVATE ole32 winmm ws2_32 comdlg32)
endif()

# ============================================================================
Expand Down
251 changes: 0 additions & 251 deletions native/intuitives_daw/Makefile

This file was deleted.

77 changes: 76 additions & 1 deletion native/intuitives_daw/src/gui/intuitives_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include <stdlib.h>
#include <string.h>

#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#include <commdlg.h>
#endif

// ============================================================================
// STATIC STATE
// ============================================================================
Expand Down Expand Up @@ -208,6 +214,72 @@
style.ItemSpacing = ImVec2(8, 6);
}

// ============================================================================
// FILE DIALOG
// ============================================================================

static bool gui_open_file_dialog(char *out_path, size_t max_len) {

Check notice on line 221 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L221

Method gui_open_file_dialog has 50 lines of code (limit is 20)

Check failure on line 221 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L221

Method gui_open_file_dialog has a cyclomatic complexity of 13 (limit is 12)
#if SG_OS == 0 // macOS
FILE *pipe = popen("osascript -e 'POSIX path of (choose file of type "

Check warning on line 223 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L223

It is generally not recommended to call out to the operating system to execute commands.

Check failure on line 223 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L223

This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality if available.
"{\"intv\"} with prompt \"Open Project\")' 2>/dev/null",
"r");
if (!pipe)
return false;
if (fgets(out_path, (int)max_len, pipe)) {
size_t len = strlen(out_path);

Check failure on line 229 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L229

Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126).

Check warning on line 229 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L229

The `strlen` family of functions does not handle strings that are not null terminated.
if (len > 0 && out_path[len - 1] == '\n') {
out_path[len - 1] = 0;
}
pclose(pipe);
return true;
}
pclose(pipe);
return false;

#elif SG_OS == 1 // Linux
// Try Zenity first
FILE *pipe = popen("zenity --file-selection --title=\"Open Project\" "

Check warning on line 241 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L241

It is generally not recommended to call out to the operating system to execute commands.

Check failure on line 241 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L241

This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality if available.
"--file-filter=\"*.intv\" 2>/dev/null",
"r");
if (!pipe)
return false;
if (fgets(out_path, (int)max_len, pipe)) {
size_t len = strlen(out_path);
if (len > 0 && out_path[len - 1] == '\n') {
out_path[len - 1] = 0;
}
pclose(pipe);
return true;
}
pclose(pipe);
return false;

#elif SG_OS == 2 // Windows
OPENFILENAMEA ofn;
memset(&ofn, 0, sizeof(ofn));

Check warning on line 259 in native/intuitives_daw/src/gui/intuitives_gui.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

native/intuitives_daw/src/gui/intuitives_gui.cpp#L259

When handling sensitive information in a buffer, it's important to ensure that the data is securely erased before the buffer is deleted or reused.
out_path[0] = 0;

ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL; // No parent window handle available easily here
ofn.lpstrFile = out_path;
ofn.nMaxFile = (DWORD)max_len;
ofn.lpstrFilter = "Intuitives Project (*.intv)\0*.intv\0All Files (*.*)\0*.*\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;

if (GetOpenFileNameA(&ofn) == TRUE) {
return true;
}
return false;

#else
return false;
#endif
}

// ============================================================================
// MENU BAR
// ============================================================================
Expand All @@ -219,7 +291,10 @@
daw_new_project(app, "Untitled");
}
if (ImGui::MenuItem("Open...", "Cmd+O")) {
// TODO: File dialog
static char path[1024];
if (gui_open_file_dialog(path, 1024)) {
daw_load_project(app, path);
}
}
if (ImGui::MenuItem("Save", "Cmd+S")) {
if (strlen(app->project.filepath) > 0) {
Expand Down