1
0

add progId generator and example

This commit is contained in:
2022-02-18 14:53:49 +08:00
parent b93e5eaf5d
commit 86864bbd09
7 changed files with 252 additions and 80 deletions

View File

@ -1,25 +1,33 @@
#include "../wfassoc/wfassoc.h"
#include <stdio.h>
#include <tchar.h>
#define COMMAND_MAX_LENGTH 128
WFAPP_PROFILEW* create_profile();
WCHAR* create_progId();
void* free_profile(WFAPP_PROFILEW* profile);
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;
}
@ -27,17 +35,18 @@ int main(int argc, char* args[]) {
//free input string
free(input_str);
return 0;
}
WFAPP_PROFILEW* create_profile() {
WFAPP_PROFILEW* profile = (WFAPP_PROFILEW*)malloc(sizeof(WFAPP_PROFILEW));
WFAPP_PROFILE* create_profile() {
WFAPP_PROFILE* profile = (WFAPP_PROFILE*)malloc(sizeof(WFAPP_PROFILE));
if (profile == NULL) return NULL;
memset(profile, 0, sizeof(WFAPP_PROFILEW));
memset(profile, 0, sizeof(WFAPP_PROFILE));
profile->WFVersion = WFVERSION;
profile->AppPath = L"";
profile->AppCommand = L"";
profile->SupportedTypes = L".png\0.jpg\0";
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);
@ -47,17 +56,18 @@ WFAPP_PROFILEW* create_profile() {
return profile;
}
wchar_t* create_progId() {
WCHAR* progid;
TCHAR* create_progId() {
TCHAR* progid = NULL;
int progIdSize;
if (WFFAILED(WFGenerateProgIDW(L"PineapplePicture", L"Image", 0, NULL, &progIdSize))) {
if (WFFAILED(WFGenerateProgID(TEXT("PineapplePicture"), TEXT("Image"), 0, NULL, &progIdSize))) {
return NULL;
}
progid = (WCHAR*)malloc(sizeof(WCHAR) * progIdSize);
progid = (TCHAR*)malloc(sizeof(TCHAR) * progIdSize);
if (progid == NULL) return NULL;
memset(progid, 0, sizeof(TCHAR) * progIdSize);
if (WFFAILED(WFGenerateProgIDW(L"PineapplePicture", L"Image", 0, NULL, &progIdSize))) {
if (WFFAILED(WFGenerateProgID(TEXT("PineapplePicture"), TEXT("Image"), 0, progid, &progIdSize))) {
free(progid);
return NULL;
}
@ -65,7 +75,7 @@ wchar_t* create_progId() {
return progid;
}
void* free_profile(WFAPP_PROFILEW* profile) {
void free_profile(WFAPP_PROFILE* profile) {
if (profile->ProgID != NULL) free(profile->ProgID);
free(profile);
}