refactor: migrate project from C++ to Rust
- establish basic Rust project layout. - move all old code into independent directory.
This commit is contained in:
81
legacy/wfassoc_example/main.c
Normal file
81
legacy/wfassoc_example/main.c
Normal file
@ -0,0 +1,81 @@
|
||||
#include "../wfassoc/wfassoc.h"
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#define COMMAND_MAX_LENGTH 128
|
||||
|
||||
WFAPP_PROFILE* create_profile();
|
||||
TCHAR* create_progId();
|
||||
void free_profile(WFAPP_PROFILE* profile);
|
||||
|
||||
int main(int argc, char* args[]) {
|
||||
|
||||
// alloc application profile
|
||||
WFAPP_PROFILE* profile = create_profile();
|
||||
if (profile == NULL) {
|
||||
puts("Error: Fail to allocating profile structure.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// alloc input string and check it
|
||||
char* input_str = malloc(sizeof(char) * (COMMAND_MAX_LENGTH + 1));
|
||||
if (input_str == NULL) return;
|
||||
|
||||
// accept input
|
||||
while (TRUE) {
|
||||
gets_s(input_str, COMMAND_MAX_LENGTH);
|
||||
if (!strcmp(input_str, "install")) {
|
||||
_tprintf(TEXT("%s\n"), profile->ProgID);
|
||||
} else if (!strcmp(input_str, "uninstall")) {
|
||||
_tprintf(TEXT("%s\n"), profile->ProgID);
|
||||
} else if (!strcmp(input_str, "quit")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//free input string
|
||||
free(input_str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
WFAPP_PROFILE* create_profile() {
|
||||
WFAPP_PROFILE* profile = (WFAPP_PROFILE*)malloc(sizeof(WFAPP_PROFILE));
|
||||
if (profile == NULL) return NULL;
|
||||
memset(profile, 0, sizeof(WFAPP_PROFILE));
|
||||
|
||||
profile->WFVersion = WFVERSION;
|
||||
profile->AppPath = TEXT("E:\\pineapple-picture\\ppic.exe");
|
||||
profile->AppCommand = TEXT("E:\\pineapple-picture\\ppic.exe \"%1\"");
|
||||
profile->SupportedTypes = TEXT(".png\0.jpg\0");
|
||||
profile->ProgID = create_progId();
|
||||
if (profile->ProgID == NULL) {
|
||||
free_profile(profile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
TCHAR* create_progId() {
|
||||
TCHAR* progid = NULL;
|
||||
int progIdSize;
|
||||
if (WFFAILED(WFGenerateProgID(TEXT("PineapplePicture"), TEXT("Image"), 0, NULL, &progIdSize))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
progid = (TCHAR*)malloc(sizeof(TCHAR) * progIdSize);
|
||||
if (progid == NULL) return NULL;
|
||||
memset(progid, 0, sizeof(TCHAR) * progIdSize);
|
||||
|
||||
if (WFFAILED(WFGenerateProgID(TEXT("PineapplePicture"), TEXT("Image"), 0, progid, &progIdSize))) {
|
||||
free(progid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return progid;
|
||||
}
|
||||
|
||||
void free_profile(WFAPP_PROFILE* profile) {
|
||||
if (profile->ProgID != NULL) free(profile->ProgID);
|
||||
free(profile);
|
||||
}
|
Reference in New Issue
Block a user