| 1 |
#ifndef MEMONOTE_H |
| 2 |
#define MEMONOTE_H |
| 3 |
|
| 4 |
class PasswordManager; |
| 5 |
class TString; |
| 6 |
class TomboURI; |
| 7 |
class Repository; |
| 8 |
|
| 9 |
//////////////////////////////////////// |
| 10 |
// Note type definition |
| 11 |
//////////////////////////////////////// |
| 12 |
|
| 13 |
#define NOTE_TYPE_NO 0 |
| 14 |
#define NOTE_TYPE_PLAIN 1 |
| 15 |
#define NOTE_TYPE_CRYPTED 2 |
| 16 |
#define NOTE_TYPE_TDT 3 |
| 17 |
|
| 18 |
//////////////////////////////////////// |
| 19 |
// represents notes |
| 20 |
//////////////////////////////////////// |
| 21 |
|
| 22 |
class MemoNote { |
| 23 |
private: |
| 24 |
virtual BOOL SaveData(PasswordManager *pMgr, const LPBYTE pData, DWORD nLen, LPCTSTR pWriteFile) = 0; |
| 25 |
static BOOL MemoNoteFactory(LPCTSTR pFile, MemoNote **ppNote); |
| 26 |
protected: |
| 27 |
LPTSTR pPath; |
| 28 |
public: |
| 29 |
/////////////////////////////////////////// |
| 30 |
// initialize |
| 31 |
|
| 32 |
MemoNote(); |
| 33 |
virtual ~MemoNote(); |
| 34 |
|
| 35 |
BOOL Init(LPCTSTR p); |
| 36 |
|
| 37 |
/////////////////////////////////////////// |
| 38 |
|
| 39 |
virtual MemoNote *GetNewInstance() const = 0; |
| 40 |
virtual LPCTSTR GetExtension() = 0; |
| 41 |
|
| 42 |
////////////////////////////////// |
| 43 |
// memo data operation members |
| 44 |
|
| 45 |
// get memo data |
| 46 |
virtual LPBYTE GetMemoBodyNative(LPCTSTR pTopDir, PasswordManager *pMgr, LPDWORD pSize) const = 0; |
| 47 |
LPTSTR GetMemoBody(LPCTSTR pTopDir, PasswordManager *pMgr) const; |
| 48 |
|
| 49 |
// save memo |
| 50 |
BOOL SaveDataT(PasswordManager *pMgr, LPCTSTR pMemo, LPCTSTR pWriteFile); |
| 51 |
|
| 52 |
////////////////////////////////// |
| 53 |
// Encryption/Decryption : |
| 54 |
// returns MemoNote instance after encryption/decryption. |
| 55 |
// set buffer to pHeadLine |
| 56 |
// if headline string is changed, *pIsModified is set to TURE and |
| 57 |
// new headline string is set to buffer. |
| 58 |
|
| 59 |
virtual MemoNote *Decrypt(LPCTSTR pTopDir, PasswordManager *pMgr, TString *pHeadLine, BOOL *pIsModified) const; |
| 60 |
|
| 61 |
////////////////////////////////// |
| 62 |
// File operation |
| 63 |
|
| 64 |
virtual BOOL DeleteMemoData(LPCTSTR pTopDir) const ; |
| 65 |
BOOL Rename(LPCTSTR pTopDir, LPCTSTR pNewName); |
| 66 |
static MemoNote *CopyMemo(LPCTSTR pTopDir, const MemoNote *pOrig, LPCTSTR pMemoPath, TString *pHeadLine); |
| 67 |
|
| 68 |
////////////////////////////////// |
| 69 |
// path related functions |
| 70 |
|
| 71 |
LPCTSTR MemoPath() const { return pPath; } |
| 72 |
BOOL SetMemoPath(LPCTSTR p); |
| 73 |
BOOL GetURI(LPCTSTR pRepoName, TomboURI *pURI) const; |
| 74 |
|
| 75 |
////////////////////////////////// |
| 76 |
// notes attributes |
| 77 |
|
| 78 |
static DWORD IsNote(LPCTSTR pFile); |
| 79 |
|
| 80 |
////////////////////////////////// |
| 81 |
// Factory method for MemoNote. |
| 82 |
// create and initialize MemoNote and return by ppNote. |
| 83 |
// |
| 84 |
// if creation failed, return FALSE. |
| 85 |
// if pFile is not memo, return TRUE and *ppNote sets to NULL. |
| 86 |
static MemoNote *MemoNoteFactory(const TomboURI *pURI); |
| 87 |
|
| 88 |
////////////////////////////////// |
| 89 |
// Headline related funcs |
| 90 |
|
| 91 |
static BOOL GetHeadLinePath(LPCTSTR pTopDir, LPCTSTR pMemoPath, LPCTSTR pHeadLine, LPCTSTR pExt, |
| 92 |
TString *pFullPath, LPCTSTR *ppNotePath, TString *pNewHeadLine); |
| 93 |
static BOOL GetHeadLineFromMemoText(LPCTSTR pMemo, TString *pHeadLine); |
| 94 |
static BOOL GetHeadLineFromFilePath(LPCTSTR pFilePath, TString *pHeadLine); |
| 95 |
|
| 96 |
}; |
| 97 |
|
| 98 |
//////////////////////////////////////// |
| 99 |
// Plain notes |
| 100 |
//////////////////////////////////////// |
| 101 |
|
| 102 |
class PlainMemoNote : public MemoNote { |
| 103 |
BOOL SaveData(PasswordManager *pMgr, const LPBYTE pData, DWORD nLen, LPCTSTR pWriteFile); |
| 104 |
|
| 105 |
public: |
| 106 |
MemoNote *GetNewInstance() const ; |
| 107 |
LPCTSTR GetExtension(); |
| 108 |
|
| 109 |
LPBYTE GetMemoBodyNative(LPCTSTR pTopDir, PasswordManager *pMgr, LPDWORD pSize) const; |
| 110 |
|
| 111 |
}; |
| 112 |
|
| 113 |
//////////////////////////////////////// |
| 114 |
// Encrypted notes |
| 115 |
//////////////////////////////////////// |
| 116 |
|
| 117 |
class CryptedMemoNote : public MemoNote { |
| 118 |
BOOL SaveData(PasswordManager *pMgr, const LPBYTE pData, DWORD nLen, LPCTSTR pWriteFile); |
| 119 |
|
| 120 |
protected: |
| 121 |
LPBYTE GetMemoBodySub(LPCTSTR pTopDir, PasswordManager *pMgr, LPDWORD pSize) const; |
| 122 |
public: |
| 123 |
MemoNote *GetNewInstance() const ; |
| 124 |
LPCTSTR GetExtension(); |
| 125 |
|
| 126 |
LPBYTE GetMemoBodyNative(LPCTSTR pTopDir, PasswordManager *pMgr, LPDWORD pSize) const; |
| 127 |
|
| 128 |
MemoNote *Decrypt(LPCTSTR pTopDir, PasswordManager *pMgr, TString *pHeadLine, BOOL *pIsModified) const; |
| 129 |
}; |
| 130 |
|
| 131 |
#endif |