#pragma once
#ifndef _COMMON_H_
#define _COMMON_H_

#include <Windows.h>

// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==

#define FILE_EXTENSION_ASAR         L".asar"
#define FILE_EXTENSION_EXE          L".exe"

#define MAX_ALPHABETICAL_DRIVES     26

#define INITIAL_ARRAY_SIZE          128
#define ARRAY_GROWTH_FACTOR         2

#define MAX_THREADS                 32
#define MIN_THREADS                 16

#define ENUMERATED_DIR_COUNT        4   // %LOCALAPPDATA%, %ProgramFiles%, %ProgramFiles(x86)%, %ProgramFiles%\WindowsApps

// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==


typedef struct _WORK_ITEM
{
    LPTHREAD_START_ROUTINE pRoutine; 
    PVOID                  pContext;
} WORK_ITEM, * PWORK_ITEM;


BOOL InitializeThreadPool();
BOOL DestroyThreadPool();
BOOL EnqueueThreadPoolWork(IN LPTHREAD_START_ROUTINE pRoutine, IN PVOID pContext);


// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==

typedef struct _ELECTRON_FUSE_STATE 
{
    BOOLEAN bIsCookieEncryptionEnabled;
    BOOLEAN bIsEmbeddedAsarIntegrityValidationEnabled;
    BOOLEAN bIsGrantFileProtocolExtraPrivilegesEnabled;
    BOOLEAN bIsLoadBrowserProcessSpecificV8SnapshotEnabled;
    BOOLEAN bIsNodeCliInspectEnabled;
    BOOLEAN bIsNodeOptionsEnabled;
    BOOLEAN bIsOnlyLoadAppFromAsarEnabled;
    BOOLEAN bIsRunAsNodeEnabled;
    BOOLEAN bHasElectronFuses;  // TRUE if ANY fuse was found
} ELECTRON_FUSE_STATE, *PELECTRON_FUSE_STATE;

typedef struct _ASAR_FILE_INFO 
{
    DWORD64     qwFileSize;
    LPWSTR      lpszAsarPath;
    LPWSTR      lpszParentExe;
} ASAR_FILE_INFO, *PASAR_FILE_INFO;

typedef struct _ELECTRON_APP_INFO 
{
    LPWSTR                  lpszExePath;
    BOOLEAN                 bVerified;
    ELECTRON_FUSE_STATE     FuseState;
    DWORD                   dwAsarCount;
    LPWSTR*                 ppszAsarFiles;
} ELECTRON_APP_INFO, *PELECTRON_APP_INFO;

typedef struct _DYNAMIC_ARRAY 
{
    LPVOID              pData;
    SIZE_T              cbElements;
    SIZE_T              cbCapacity;
    SIZE_T              cbElementSize;
    CRITICAL_SECTION    CriticalSection;
} DYNAMIC_ARRAY, *PDYNAMIC_ARRAY;

// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==


PDYNAMIC_ARRAY DynamicArrayCreate(IN SIZE_T cbElementSize);
BOOL DynamicArrayAdd(IN PDYNAMIC_ARRAY pArray, IN LPVOID pElement);
LPVOID DynamicArrayGet(IN PDYNAMIC_ARRAY pArray, IN SIZE_T cbElementIndex);
VOID DynamicArrayDestroy(IN PDYNAMIC_ARRAY pArray);
PCHAR FormatNumberUnit(IN OUT PCHAR pszBuffer, IN DWORD dwBufferSize, IN DWORD64 qwBytes);
LPWSTR HeapAllocStrDuplicateW(IN LPWSTR szStrToDuplicate);
BOOL FileMatchExtension(IN LPWSTR szFileName, IN LPCWSTR pwszExtension);

// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==



#endif // !_COMMON_H_
