//****************************************************************************
//
// Copyright (c) ALTAP, spol. s r.o. All rights reserved.
//
// This is a part of the Altap Salamander SDK library.
//
// The SDK is provided "AS IS" and without warranty of any kind and 
// ALTAP EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE and NON-INFRINGEMENT.
//
//****************************************************************************

#ifndef __UNFAT_H
#define __UNFAT_H


// obecne rozhrani Salamandera - platne od startu az do ukonceni pluginu
extern CSalamanderGeneralAbstract *SalamanderGeneral;

// rozhrani pro praci se soubory - platne od startu az do ukonceni pluginu
extern CSalamanderSafeFileAbstract *SalamanderSafeFile;

// casto pouzita chybova hlaska
extern const char *LOW_MEMORY;

// aktualni hodnota konfiguracni promenne Salamandera SALCFG_SORTBYEXTDIRSASFILES
extern int SortByExtDirsAsFiles;

// nulove/male soubory trvaji aspon jako soubory s velikosti COPY_MIN_FILE_SIZE
#define COPY_MIN_FILE_SIZE CQuadWord(1024, 0) // nesmi byt mensi nez 1 

// ****************************************************************************
//
// CPluginInterface
//

class CPluginInterfaceForArchiver: public CPluginInterfaceForArchiverAbstract
{
  public:
    virtual BOOL WINAPI ListArchive(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                    CSalamanderDirectoryAbstract *dir,
                                    CPluginDataInterfaceAbstract *&pluginData);
    virtual BOOL WINAPI UnpackArchive(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                      CPluginDataInterfaceAbstract *pluginData, const char *targetDir,
                                      const char *archiveRoot, SalEnumSelection next, void *nextParam);
    virtual BOOL WINAPI UnpackOneFile(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                      CPluginDataInterfaceAbstract *pluginData, const char *nameInArchive,
                                      const CFileData *fileData, const char *targetDir,
                                      const char *newFileName, BOOL *renamingNotSupported);
    virtual BOOL WINAPI PackToArchive(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                      const char *archiveRoot, BOOL move, const char *sourcePath,
                                      SalEnumSelection2 next, void *nextParam) {return FALSE;}
    virtual BOOL WINAPI DeleteFromArchive(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                          CPluginDataInterfaceAbstract *pluginData, const char *archiveRoot,
                                          SalEnumSelection next, void *nextParam) {return FALSE;}
    virtual BOOL WINAPI UnpackWholeArchive(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                           const char *mask, const char *targetDir, BOOL delArchiveWhenDone,
                                           CDynamicString *archiveVolumes);
    virtual BOOL WINAPI CanCloseArchive(CSalamanderForOperationsAbstract *salamander, const char *fileName,
                                        BOOL force, int panel) {return TRUE;}
    virtual BOOL WINAPI GetCacheInfo(char *tempPath, BOOL *ownDelete, BOOL *cacheCopies) {return FALSE;}
    virtual void WINAPI DeleteTmpCopy(const char *fileName, BOOL firstFile) {}
    virtual BOOL WINAPI PrematureDeleteTmpCopy(HWND parent, int copiesCount) {return FALSE;}
};

class CPluginInterface: public CPluginInterfaceAbstract
{
  public:
    virtual void WINAPI About(HWND parent);

    virtual BOOL WINAPI Release(HWND parent, BOOL force);

    virtual void WINAPI LoadConfiguration(HWND parent, HKEY regKey, CSalamanderRegistryAbstract *registry);
    virtual void WINAPI SaveConfiguration(HWND parent, HKEY regKey, CSalamanderRegistryAbstract *registry);
    virtual void WINAPI Configuration(HWND parent) {};

    virtual void WINAPI Connect(HWND parent, CSalamanderConnectAbstract *salamander);

    virtual void WINAPI ReleasePluginDataInterface(CPluginDataInterfaceAbstract *pluginData);

    virtual CPluginInterfaceForArchiverAbstract * WINAPI GetInterfaceForArchiver();
    virtual CPluginInterfaceForViewerAbstract * WINAPI GetInterfaceForViewer() {return NULL;}
    virtual CPluginInterfaceForMenuExtAbstract * WINAPI GetInterfaceForMenuExt() {return NULL;}
    virtual CPluginInterfaceForFSAbstract * WINAPI GetInterfaceForFS() {return NULL;}
    virtual CPluginInterfaceForThumbLoaderAbstract * WINAPI GetInterfaceForThumbLoader() {return NULL;}

    virtual void WINAPI Event(int event, DWORD param);
    virtual void WINAPI ClearHistory(HWND parent) {}
    virtual void WINAPI AcceptChangeOnPathNotification(const char *path, BOOL includingSubdirs) {}

    virtual BOOL WINAPI UninstallUnregisteredComponents(HWND parent, char *componentsDescr, BOOL *uninstallSPL,
                                                        BOOL *uninstallLangDir, const char *pluginDir,
                                                        CDynamicString *deleteFileList) {return FALSE;}

    virtual void WINAPI PasswordManagerEvent(HWND parent, int event) {}
};

extern HINSTANCE DLLInstance; // handle k SPL-ku - jazykove nezavisle resourcy
extern HINSTANCE HLanguage;   // handle k SLG-cku - jazykove zavisle resourcy

//extern DWORD Options;// konfigurace
struct COptions
{
  BOOL ClearReadOnly;       // Clear read-only attribute when copying from archive
  BOOL SessionAsDirectory;  // Show session as directory (allow access to all sessions)
};

extern COptions Options;  // konfigurace

char *LoadStr(int resID);
void GetInfo(char *buffer, FILETIME * lastWrite, unsigned size);
BOOL Error(int resID, BOOL quiet = FALSE, ...);
BOOL Error(char *msg, DWORD err, BOOL quiet = FALSE);
BOOL SysError(int title, int error, ...);

//int lstrcmpn(const char *str1, const char *str2, int len);

// Helpers
#define LOWDWORD(x) (DWORD)(x)
#define HIDWORD(x) (DWORD)((x) >> 32)


#define DUMP_MEM_OBJECTS

#if defined(DUMP_MEM_OBJECTS) && defined(_DEBUG)
#define CRT_MEM_CHECKPOINT _CrtMemState ___CrtMemState; _CrtMemCheckpoint(&___CrtMemState);
#define CRT_MEM_DUMP_ALL_OBJECTS_SINCE _CrtMemDumpAllObjectsSince(&___CrtMemState);

#else //DUMP_MEM_OBJECTS
#define CRT_MEM_CHECKPOINT ;
#define CRT_MEM_DUMP_ALL_OBJECTS_SINCE ;

#endif //DUMP_MEM_OBJECTS

#endif //__UNFAT_H