Skip to content

Commit

Permalink
Last few changes before release
Browse files Browse the repository at this point in the history
Minor tweaks to text, code, build system
  • Loading branch information
petabyt committed Jan 16, 2024
1 parent 2fc7520 commit 3254f02
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config.mak
SD_BACKUP
mlinstall
unix-gtk
Expand Down
2 changes: 1 addition & 1 deletion assets/mlinstall.desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Desktop Entry]
Name=mlinstall
Exec=mlinstall
Exec=linux.out
Icon=mlinstall
Type=Application
Categories=Utility
Expand Down
2 changes: 1 addition & 1 deletion camlib
1 change: 0 additions & 1 deletion config.mak

This file was deleted.

1 change: 0 additions & 1 deletion linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mac.out: $(FILES)
mlinstall-x86_64.AppImage: linux.out
linuxdeploy --appdir=AppDir --executable=linux.out -d assets/mlinstall.desktop -i assets/mlinstall.png
appimagetool AppDir
rm mlinstall

.PHONY: pkg
pkg: mac.out
Expand Down
5 changes: 1 addition & 4 deletions src/drive-unix.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Common filesystem drive code for Unix
// fopen/fwrite/fseek Works on Windows,
// just but won't write to the drive, so we
// have to rewrite everything :)
// Common filesystem drive code for Linux/Darwin

#ifdef WIN32
#error "not windows code"
Expand Down
25 changes: 10 additions & 15 deletions src/drive-win.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
// Windows fileapi based code
#ifdef WIN32
// fopen/fwrite/fseek works on Windows, just but won't write to the drive, so this
// is a separate implementation

#include <stdio.h>
#include <windows.h>

BOOL IsUserAnAdmin();

#include "drive.h"
#include "exfat.h"

// Bootsector size
#define SIZE 512
#define BOOTSECTOR_SIZE 512

char bootsector[SIZE];
DWORD bytesRead = 0;
static char bootsector[BOOTSECTOR_SIZE];
static DWORD bytesRead = 0;

HANDLE d;
static HANDLE d;

int drive_getfs()
{
SetFilePointer(d, 0, NULL, FILE_BEGIN);
ReadFile(d, bootsector, SIZE, &bytesRead, NULL);
ReadFile(d, bootsector, BOOTSECTOR_SIZE, &bytesRead, NULL);

if (!strncmp(bootsector + 54, "FAT16 ", 8)) {
return FAT16;
Expand All @@ -47,7 +44,7 @@ static int exfat_write(int location, int length, void *bytes)

// Write to specific spot in
SetFilePointer(d, sector, NULL, FILE_BEGIN);
ReadFile(d, bootsector, SIZE, &bytesRead, NULL);
ReadFile(d, bootsector, BOOTSECTOR_SIZE, &bytesRead, NULL);
memcpy(bootsector + (offset % 512), bytes, length);
SetFilePointer(d, sector, NULL, FILE_BEGIN);
WriteFile(d, bootsector, 512, &bytesRead, NULL);
Expand All @@ -60,15 +57,15 @@ void flag_write(long offset, char string[])
char old_flag[16] = { 0 };

SetFilePointer(d, 0, NULL, FILE_BEGIN);
ReadFile(d, bootsector, SIZE, &bytesRead, NULL);
ReadFile(d, bootsector, BOOTSECTOR_SIZE, &bytesRead, NULL);

memcpy(old_flag, bootsector + offset, strlen(string) % sizeof(old_flag));
printf("Current Flag: %s\n", old_flag);
memcpy(bootsector + offset, string, strlen(string));
printf("New Flag: %s\n", string);

SetFilePointer(d, 0, NULL, FILE_BEGIN);
if (!WriteFile(d, bootsector, SIZE, &bytesRead, NULL)) {
if (!WriteFile(d, bootsector, BOOTSECTOR_SIZE, &bytesRead, NULL)) {
printf("Error writing to drive: %ld\n", GetLastError());
return;
}
Expand Down Expand Up @@ -189,5 +186,3 @@ void drive_dump(char name[]) {
fwrite(dump, 1, TEMP_DUMP_SIZE, f);
fclose(f);
}

#endif
1 change: 1 addition & 0 deletions src/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define T_ABOUT "About"
#define T_CARD "Card"
#define T_DEV_NOT_FOUND "Couldn't find a PTP/USB device."
#define T_CANON_NOT_FOUND_FMT "No Canon device found (%d)"
#define T_DRIVE_NOT_FOUND "Couldn't find card. Make sure the EOS_DIGITAL card is mounted."
#define T_DRIVE_NOT_SUPPORTED "Only ExFAT, FAT32, and FAT16 cards are supported."
#define T_DRIVE_ERROR "Error opening drive."
Expand Down
7 changes: 4 additions & 3 deletions src/libui.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "lang.h"
#include "drive.h"

// 200ms event thread loop
#define EVENT_THREAD_INTERVAL_US (1000 * 200)

struct AppGlobalState {
Expand Down Expand Up @@ -152,7 +153,6 @@ static void ui_flip_status(void *data) {

app.ticks++;

// TODO: don't run ui code in ptp thread
uiLabelSetText(app.title_text, buffer);
}

Expand Down Expand Up @@ -360,6 +360,7 @@ static void *app_disconnect(void *arg) {

int on_closing(uiWindow *w, void *data)
{
// TODO: close down threads
uiQuit();
return 1;
}
Expand Down Expand Up @@ -393,8 +394,8 @@ static uiControl *page_usb(void)
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);

label = uiNewLabel("Camera not connected");
uiBoxAppend(vbox, uiControl(label), 0);
//label = uiNewLabel("Camera not connected");
//uiBoxAppend(vbox, uiControl(label), 0);
button = uiNewButton(T_CONNECT);
app.connect_button = button;
uiBoxAppend(vbox, uiControl(button), 0);
Expand Down
37 changes: 22 additions & 15 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ int main (int argc, char ** argv) {
return 1;
}

printf("Uploading '%s' to cam as '%s'", argv[i + 1], argv[i + 2]);
printf("Uploading '%s' to cam as '%s'\n", argv[i + 1], argv[i + 2]);

int rc = ptp_chdk_upload_file(&ptp_runtime, argv[i + 1], argv[i + 2]);
if (rc) return rc;

printf("File uploaded\n");

return ptp_connect_deinit();
} else if (!strcmp(argv[i], "--test")) {
if (app_test()) return 1;
if (app_test()) return 1;
if (app_test()) return 1;
return 1;
if (app_test()) {
puts("Test failed\n");
return 1;
}
return 0;
}
}

Expand All @@ -69,15 +72,19 @@ int main (int argc, char ** argv) {
}

int app_test() {
if (ptp_connect_init()) {
printf("%s\n", T_DEV_NOT_FOUND);
return 1;
}
for (int i = 0; i < 3; i++) {
if (ptp_connect_init()) {
printf("%s\n", T_DEV_NOT_FOUND);
return 1;
}

// TODO: .. do some stress test
puts("Connected");

// TODO: .. do some stress test
puts("Connected");
if (ptp_connect_deinit()) return 1;
}

return ptp_connect_deinit();
return 0;
}

int ptp_connect_deinit() {
Expand All @@ -97,8 +104,8 @@ int ptp_connect_init() {
// For LibWPD, this will work just fine to detect cameras
rc = ptp_device_init(&ptp_runtime);
if (rc) {
log_print(T_DEV_NOT_FOUND);
return rc;
log_print(T_CANON_NOT_FOUND_FMT, attempts - 1);
return PTP_NO_DEVICE;
}
#else
// TODO: libWPD doesn't have this yet
Expand All @@ -115,7 +122,7 @@ int ptp_connect_init() {
}

if (selected == NULL) {
log_print("No Canon device found (%d)", attempts - 1);
log_print(T_CANON_NOT_FOUND_FMT, attempts - 1);
return PTP_NO_DEVICE;
}

Expand Down

0 comments on commit 3254f02

Please sign in to comment.