1
0
Files
wfassoc/legacy/wfassoc/wfassoc_utils.h
yyc12345 e06fcdf53b refactor: migrate project from C++ to Rust
- establish basic Rust project layout.
- move all old code into independent directory.
2025-10-04 22:04:30 +08:00

136 lines
4.2 KiB
C

#if !defined(_YYCDLL_WFASSOC_UTILS_H__IMPORTED_)
#define _YYCDLL_WFASSOC_UTILS_H__IMPORTED_
#include <Windows.h>
#include <inttypes.h>
// useful macro
#define WFNEW(type) ((type*)malloc(sizeof(type)))
#define WFNEW_ARRAY(type) ((type*)malloc(sizeof(type)*count);)
#define WFVERSION 0
#define WFSUCCESS(expr) (!expr)
#define WFFAILED(expr) expr
/// <summary>
/// wfassoc Error Enum
/// </summary>
typedef enum _WFERROR {
/// <summary>
/// All operation done successfully
/// </summary>
WFERROR_OK = 0,
/// <summary>
/// The filed `WFVersion` in Profile Struct is not matched. It usually mean that currently used DLL is not matched with the DLL when compiling this application.
/// </summary>
WFERROR_INVALID_VERSION = 1,
/// <summary>
/// The buffer in some operations is insufficient, please try expanding buffer.
/// </summary>
WFERROR_INSUFFICIENT_BUFFER = 2,
/// <summary>
/// Some essential pointer variable is NULL.
/// </summary>
WFERROR_NULLPTR = 3,
WFERROR_WIN32 = 5,
WFERROR_ALLOC = 6,
WFERROR_END_OF_TAIL = 7,
WFERROR_CRT = 8,
WFERROR_INVALID_ARGUMENTS = 9
}WFERROR;
/// <summary>
/// wfassoc Profile Struct
/// </summary>
typedef struct _WFAPP_PROFILE {
/// <summary>
/// wfassoc version. Fill it with `WFVERSION` in your application. This field is used for version checking.
/// </summary>
uint32_t WFVersion;
/// <summary>
/// The path to locate your application.
/// </summary>
wchar_t* AppPath;
/// <summary>
/// The command will be executed when opening files.
/// </summary>
wchar_t* AppCommand;
/// <summary>
/// Your application's ProgID.
/// For more detail about how to create your ProgID, please browse: https://docs.microsoft.com/en-us/windows/win32/shell/fa-progids
/// We also provide a generator for creating legacy ProgID. Use `WFGenerateProgID` to create a legacy ProgID.
/// </summary>
wchar_t* ProgID_Vendor;
wchar_t* ProgID_Component;
uint32_t ProgID_Version;
/// <summary>
/// Your application supported file extensions.
/// The structure of this field is connecting all supported extensions with dot(.) end to end. For example:
/// `.jpg\0.png\0.gif\0`
/// </summary>
wchar_t* SupportedTypes;
BOOL RegisterForAllUsers;
BOOL SetAsDefault;
BOOL ShowInOpenWithMenu;
BOOL UseOpenWithList;
}WFAPP_PROFILE;
typedef struct _WFAPP_INTERNAL_PROFILE {
WFString* AppPath;
WFString* AppBasePath;
WFString* AppFileName;
WFString* ProgID;
WFString* AppCommand;
WFLinkedList* SupportedTypes;
BOOL RegisterForAllUsers;
BOOL SetAsDefault;
BOOL ShowInOpenWithMenu;
BOOL UseOpenWithList;
}WFAPP_INTERNAL_PROFILE;
typedef struct _WFString {
wchar_t* mRawData;
uint32_t mLength;
uint32_t mCapacity;
uint32_t mRealLength;
uint32_t mRealCapacity;
}WFString;
WFERROR WFString_Alloc_Wchar(WFString** strl, const wchar_t* raw_data);
WFERROR WFString_Alloc_Char(WFString** strl, const char* raw_data, BOOL is_utf8);
WFERROR WFString_Alloc_Capacity(WFString** strl, uint32_t size);
WFERROR WFString_Alloc(WFString** strl);
WFERROR WFString_Free(WFString* strl);
WFERROR WFString_Resize(WFString* strl, uint32_t new_size);
WFERROR WFString_GetData(WFString* strl, wchar_t** pdata);
WFERROR WFString_SetData(WFString* strl, const wchar_t* data);
WFERROR WFString_GetLength(WFString* strl, uint32_t* len);
WFERROR WFString_Printf(WFString* strl, const wchar_t* format, ...);
WFERROR WFString_Concat_Wchar(WFString* strl, const wchar_t* extra);
WFERROR WFString_Concat_String(WFString* strl, WFString* extra);
WFERROR WFString_SubString(WFString* strl, WFString* substring, uint32_t start_index, uint32_t length);
typedef WFERROR(*WFLinkedListNode_FreeDataFunc)(void* data);
typedef struct _WFLinkedListNode {
void* mRawData;
WFLinkedListNode* mNext;
}WFLinkedListNode;
typedef struct _WFLinkedList {
WFLinkedListNode* mHead;
WFLinkedListNode* mTail;
uint32_t mLength;
}WFLinkedList;
WFERROR WFLinkedList_Alloc(WFLinkedList** list);
WFERROR WFLinkedList_Free(WFLinkedList* list);
WFERROR WFLinkedList_Free_Full(WFLinkedList* list, WFLinkedListNode_FreeDataFunc free_func);
WFERROR WFLinkedList_Add(WFLinkedList* list, void* data);
WFERROR WFLinkedList_NodeIterator(WFLinkedList* list, WFLinkedListNode** node_ptr);
WFERROR WFLinkedListNode_GetData(WFLinkedListNode* node, void** pdata);
#endif