From e70ab80a96eb82a9fb1152af3b3ed25c5f253cc0 Mon Sep 17 00:00:00 2001 From: Maximus5 Date: Sat, 26 Dec 2020 20:32:41 +0100 Subject: [PATCH] dir_so: version 3.0.0.7 * don't use heap to allocate small structures * fix leading space in some file names * test console tool to list contents --- Dir_b3/Dir_fmt_exe.cpp | 251 ++++++++++++++++++++++---------- Dir_b3/dir.cpp | 265 +++++++++++++++++++--------------- Dir_b3/dir_b3.rc | 194 ++++++++++++------------- Dir_b3/dir_so.vcxproj | 2 + Dir_b3/dir_so.vcxproj.filters | 4 + Dir_b3/resource.h | 1 + 6 files changed, 430 insertions(+), 287 deletions(-) diff --git a/Dir_b3/Dir_fmt_exe.cpp b/Dir_b3/Dir_fmt_exe.cpp index 25fdf1c..952329a 100644 --- a/Dir_b3/Dir_fmt_exe.cpp +++ b/Dir_b3/Dir_fmt_exe.cpp @@ -3,12 +3,14 @@ #include #include +#include +#include #include #include #include -#include "\VCProject\MLib\farsdk\ascii\plugin.hpp" -#include "\VCProject\MLib\farsdk\ascii\fmt.hpp" +#include "plugin.hpp" +#include "fmt.hpp" int help(); int fail(int nCode); @@ -17,153 +19,256 @@ int WINAPI _export GetArcItem(struct PluginPanelItem *Item, struct ArcItemInfo * BOOL WINAPI _export CloseArchive(struct ArcInfo *Info); int CreateItem ( PluginPanelItem& Item ); -BOOL lbNoPath=FALSE; +enum class WorkMode +{ + ExtractNoPath, + ExtractWithPath, + Information, + ListFiles, +}; + +WorkMode work_mode; int main(int argc, char* argv[]) { int nRc = 0; - printf ("Arg count: %i\n", argc); - for (int i=0; i psNeeds; - TCHAR *psz = pszList; - TCHAR *pszLine = NULL; - while ((pszLine=_tcschr(psz, _T('\r')))) { + + std::vector psNeeds; + std::unique_ptr pszList; + HANDLE hList = INVALID_HANDLE_VALUE; + while (work_mode == WorkMode::ExtractNoPath || work_mode == WorkMode::ExtractWithPath) { + hList = CreateFile(argv[3], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, 0); + if (hList == INVALID_HANDLE_VALUE) { + nRc = 102; break; + } + DWORD dwSize, dwHigh = 0; + dwSize = GetFileSize(hList, &dwHigh); + if (dwHigh != 0 || dwSize == static_cast(-1) || dwSize == 0) { + nRc = 103; break; + } + + // ReSharper disable once CppJoinDeclarationAndAssignment + pszList = std::make_unique(dwSize + 1); + if (!pszList) { + nRc = 104; break; + } + if (!ReadFile(hList, pszList.get(), dwSize, &dwSize, 0)) { + nRc = 105; break; + } + + OemToCharBuff(pszList.get(), pszList.get(), dwSize); + + TCHAR* psz = pszList.get(); + TCHAR* pszLine = nullptr; + while ((pszLine = _tcschr(psz, _T('\r')))) { *pszLine = 0; - if (pszLine[1]==_T('\n')) pszLine+=2; else pszLine++; + if (pszLine[1] == _T('\n')) pszLine += 2; else pszLine++; psNeeds.push_back(psz); psz = pszLine; } + break; + } - PluginPanelItem Item; memset(&Item, 0, sizeof(Item)); - ArcItemInfo Info; memset(&Info, 0, sizeof(Info)); + if (hList != INVALID_HANDLE_VALUE) + CloseHandle(hList); - //MessageBox(NULL, "Wait", "Dir.fmt.exe", MB_OK); + const auto prevCp = GetConsoleOutputCP(); + uint32_t fileCount = 0; + uint32_t dirCount = 0; + if (nRc == 0) + { + SetConsoleOutputCP(1251); + + PluginPanelItem item{}; + ArcItemInfo info{}; + + //MessageBox(nullptr, "Wait", "Dir.fmt.exe", MB_OK); + + wchar_t utfBuffer[MAX_PATH + 32]; + bool switchedToUtf8 = false; + HANDLE hStdOut = NULL; //TCHAR szFromDir[MAX_PATH+1]; szFromDir[0]=0; - while (GETARC_SUCCESS==GetArcItem(&Item, &Info)) { - OemToCharBuff(Item.FindData.cFileName, Item.FindData.cFileName, strlen(Item.FindData.cFileName)); - if (Item.FindData.cFileName[0]==_T('<')) continue; // - //if (Item.FindData.dwFileAttributes&&FILE_ATTRIBUTE_DIRECTORY) continue; - if (strchr(Item.FindData.cFileName,'\\')) { - int nDbg=0; + while (GETARC_SUCCESS == GetArcItem(&item, &info)) { + if (item.UserData == CP_UTF8) + { + if (!hStdOut) + { + hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + switchedToUtf8 = true; + } + } + + if (item.UserData == CP_OEMCP) + { + OemToCharBuff(item.FindData.cFileName, item.FindData.cFileName, strlen(item.FindData.cFileName)); + } + + if (item.FindData.cFileName[0] == _T('<')) + continue; // + //if (Item.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; + if (strchr(item.FindData.cFileName, '\\')) { + std::ignore = 0; + } + + if (item.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + ++dirCount; + else + ++fileCount; + + if (work_mode == WorkMode::ListFiles) { + if (switchedToUtf8 && hStdOut && hStdOut != INVALID_HANDLE_VALUE && item.UserData == CP_UTF8) + { + swprintf_s(utfBuffer, L"%c '", (item.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 'D' : 'F'); + MultiByteToWideChar(CP_UTF8, 0, item.FindData.cFileName, -1, utfBuffer + 3, MAX_PATH + 1); + wcscat_s(utfBuffer, L"'\n"); + DWORD written = 0; + WriteConsoleW(hStdOut, utfBuffer, wcslen(utfBuffer), &written, nullptr); + } + else + { + printf("%c '%s'\n", (item.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 'D' : 'F', + item.FindData.cFileName); + } } - for (std::vector::iterator iter=psNeeds.begin(); iter!=psNeeds.end(); iter++) + // ReSharper disable once IdentifierTypo + for (auto* psTest : psNeeds) { - TCHAR *psTest = *iter; - BOOL lbOurFile=FALSE; - if (_tcsnicmp(psTest, Item.FindData.cFileName, strlen(psTest))==0) + BOOL lbOurFile = FALSE; + if (_tcsnicmp(psTest, item.FindData.cFileName, strlen(psTest)) == 0) { - lbOurFile=TRUE; - if (Item.FindData.dwFileAttributes&&FILE_ATTRIBUTE_DIRECTORY) { - psTest+=_tcslen(psTest); - if (*(psTest-1)!=_T('\\')) { - if (psTest[1]!='\n') { + lbOurFile = TRUE; + if (item.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + psTest += _tcslen(psTest); + if (*(psTest - 1) != _T('\\')) { + if (psTest[1] != _T('\n')) { nRc = 200; break; } - *psTest=_T('\\'); + *psTest = _T('\\'); psTest[1] = 0; } } } if (lbOurFile) { - nRc = CreateItem(Item); + nRc = CreateItem(item); break; } } } - CloseArchive(NULL); + CloseArchive(nullptr); } - free(pszList); - printf("Rc: %i\n", nRc); - SetConsoleOutputCP(866); + + if (work_mode == WorkMode::Information || work_mode == WorkMode::ListFiles) + printf("Directories: %u\nFiles: %u\n", dirCount, fileCount); + + if (nRc != 0) + printf("Can't extract\nRc: %i\n", nRc); + else + printf("Rc: %i\n", nRc); + SetConsoleOutputCP(prevCp); return nRc; } int help() { - printf ("Dir.fmt.exe {e|x} \"dir_file\" \"file_list\"\n"); + printf("Dir.fmt.exe {e|x} \"dir_file\" \"file_list\"\n"); return 100; } int fail(int nCode) { - printf ("Can't extract!\n"); + printf("Can't extract!\nRc: %i\n", nCode); return nCode; } -int CreateItem ( PluginPanelItem& Item ) +int CreateItem(PluginPanelItem& Item) { int nRc = 0; - DWORD dwLastError=0; + // ReSharper disable once CppEntityAssignedButNoRead + DWORD dwLastError = 0; TCHAR* pszFile = Item.FindData.cFileName; - if (lbNoPath) { - TCHAR *pszSlash = _tcsrchr(pszFile, _T('\\')); + if (work_mode == WorkMode::ExtractNoPath) { + TCHAR* pszSlash = _tcsrchr(pszFile, _T('\\')); if (pszSlash) - pszFile = pszSlash+1; + pszFile = pszSlash + 1; } - if (Item.FindData.dwFileAttributes&&FILE_ATTRIBUTE_DIRECTORY) { + if (Item.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { printf("Creating folder: %s", pszFile); - CreateDirectory(pszFile, NULL); + CreateDirectory(pszFile, nullptr); printf("\n"); - } else { + } + else { printf("Creating file: %s", pszFile); - HANDLE hFile = CreateFile(pszFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL/*Item.FindData.dwFileAttributes*/, NULL); + // ReSharper disable once CppLocalVariableMayBeConst + HANDLE hFile = CreateFile(pszFile, GENERIC_WRITE, FILE_SHARE_READ, nullptr, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL/*Item.FindData.dwFileAttributes*/, nullptr); - if (hFile==INVALID_HANDLE_VALUE) { + if (hFile == INVALID_HANDLE_VALUE) { nRc = 110; - } else { - SetFilePointer(hFile, Item.FindData.nFileSizeLow, (long*)&Item.FindData.nFileSizeHigh, FILE_BEGIN); + } + else { + SetFilePointer(hFile, Item.FindData.nFileSizeLow, reinterpret_cast(&Item.FindData.nFileSizeHigh), FILE_BEGIN); SetEndOfFile(hFile); - if (!SetFileTime(hFile, NULL, NULL, &Item.FindData.ftLastWriteTime)) + if (!SetFileTime(hFile, nullptr, nullptr, &Item.FindData.ftLastWriteTime)) dwLastError = GetLastError(); CloseHandle(hFile); - if (!SetFileAttributes(pszFile, Item.FindData.dwFileAttributes|FILE_ATTRIBUTE_HIDDEN)) + if (!SetFileAttributes(pszFile, Item.FindData.dwFileAttributes | FILE_ATTRIBUTE_HIDDEN)) dwLastError = GetLastError(); } printf("\n"); } + + std::ignore = dwLastError; return nRc; } diff --git a/Dir_b3/dir.cpp b/Dir_b3/dir.cpp index 22e0f27..d9c7d8b 100644 --- a/Dir_b3/dir.cpp +++ b/Dir_b3/dir.cpp @@ -7,6 +7,7 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include +#include #include "plugin.hpp" #include "fmt.hpp" #include @@ -88,7 +89,7 @@ BOOL APIENTRY DllMain( HMODULE hModule, }; struct DirInfo; -DirInfo* gpCur = NULL; +DirInfo* gpCur = nullptr; //static struct PluginStartupInfo Info; struct DirInfo @@ -176,31 +177,30 @@ struct DirInfo return true; }; - BOOL openArchive(int *Type) + BOOL openArchive(int* Type) { - //Handle=CreateFile(Name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, - // FILE_FLAG_SEQUENTIAL_SCAN, NULL); - if (Handle!=INVALID_HANDLE_VALUE) + //Handle=CreateFile(Name, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, + // FILE_FLAG_SEQUENTIAL_SCAN, nullptr); + if (Handle != INVALID_HANDLE_VALUE) { - MapHandle=CreateFileMapping(Handle, NULL, PAGE_READONLY, 0, 0, NULL); + MapHandle = CreateFileMapping(Handle, nullptr, PAGE_READONLY, 0, 0, nullptr); if (MapHandle) { - Pos = Data = (char *)MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0); + Pos = Data = static_cast(MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0)); if (Data) { - *Type=0; - *Prefix=0; nPrefixLen = 0; - *Descrip=0; - nSkipLen=0; - Edge = Data + GetFileSize(Handle, NULL); + *Type = 0; + *Prefix = 0; nPrefixLen = 0; + *Descrip = 0; + nSkipLen = 0; + Edge = Data + GetFileSize(Handle, nullptr); - PluginPanelItem* Item = (PluginPanelItem*)calloc(1,sizeof(PluginPanelItem)); - ArcItemInfo* Info = (ArcItemInfo*)calloc(1,sizeof(ArcItemInfo)); - bool lbRc = (getArcItem(Item, Info) == GETARC_SUCCESS); - free(Item); free(Info); + PluginPanelItem Item{}; + ArcItemInfo Info{}; + const bool lbRc = (getArcItem(&Item, &Info) == GETARC_SUCCESS); nStrLen = nSkipLen = 0; - *Prefix=0; nPrefixLen = 0; + *Prefix = 0; nPrefixLen = 0; Pos = Data; if (lbRc) @@ -210,31 +210,31 @@ struct DirInfo return true; } } - CloseHandle(MapHandle); MapHandle = NULL; + CloseHandle(MapHandle); MapHandle = nullptr; } CloseHandle(Handle); } - Handle = NULL; + Handle = nullptr; return false; - }; + } - int getArcItem(struct PluginPanelItem *Item, struct ArcItemInfo *Info) + int getArcItem(struct PluginPanelItem* Item, struct ArcItemInfo* Info) { - static const char *LabelHeader[]={ " Том", " Volume in" }; - static const char *SerialHeader[]={ " Серийный", " Volume Serial" }; - static const char *DirHeader[]={ " Содержимое папки", " Directory of" }; - static const char *DirEndHeader[]={ " Всего файлов:", " Total Files" }; - static char DirID[]=""; - static char JunID[]=""; + static const char* LabelHeader[] = { " Том", " Volume in" }; + static const char* SerialHeader[] = { " Серийный", " Volume Serial" }; + static const char* DirHeader[] = { " Содержимое папки", " Directory of" }; + static const char* DirEndHeader[] = { " Всего файлов:", " Total Files" }; + static char DirID[] = ""; + static char JunID[] = ""; //char* Buf = (char*)malloc(4096); - bool First=false; - size_t nLines=0; + bool First = false; + size_t nLines = 0; //if (isBtanch) nSkipLen=0; - while (GetS(Buf,ARRAYSIZE(Buf)-2)) + while (GetS(Buf, ARRAYSIZE(Buf) - 2)) { nLines++; - if ((First = Compare(Buf, LabelHeader[0], true)) || Compare(Buf, LabelHeader[1])) + if (((First = Compare(Buf, LabelHeader[0], true))) || Compare(Buf, LabelHeader[1])) { FormatOk = true; isRus = First; @@ -252,13 +252,13 @@ struct DirInfo // 26.11.2008 Maks - //lstrcpy(Descrip, " Label:"); - Descrip[0]=0; + Descrip[0] = 0; // 26.11.2008 Maks - лидирующий пробел не нужен //if (isRus?*(Buf+20)=='и':*(Buf+19)=='i' ) lstrcat(Descrip, Buf+(isRus?31:21)); - char *lpszPtr = NULL; - if (isRus?*(Buf+20)=='и':*(Buf+19)=='i' ) lpszPtr = Buf+(isRus?31:21); + char* lpszPtr = nullptr; + if (isRus ? *(Buf + 20) == 'и' : *(Buf + 19) == 'i') lpszPtr = Buf + (isRus ? 31 : 21); if (!lpszPtr) continue; - while (*lpszPtr==' ') lpszPtr++; + while (*lpszPtr == ' ') lpszPtr++; // 26.11.2008 Maks - Сразу вернем элемент если есть метка диска if (!*lpszPtr) continue; @@ -266,17 +266,19 @@ struct DirInfo lstrcpy(Item->FindData.cFileName, "=(MAX_PATH-20)) lpszPtr[MAX_PATH-20] = 0; + if (lstrlenA(lpszPtr) >= (MAX_PATH - 20)) + lpszPtr[MAX_PATH - 20] = 0; lstrcat(Item->FindData.cFileName, lpszPtr); lstrcat(Item->FindData.cFileName, ">"); - Item->FindData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY; + Item->FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; + Item->UserData = 0; SYSTEMTIME st; GetSystemTime(&st); FILETIME ft; - SystemTimeToFileTime(&st,&ft); - LocalFileTimeToFileTime(&ft,&Item->FindData.ftLastWriteTime); + SystemTimeToFileTime(&st, &ft); + LocalFileTimeToFileTime(&ft, &Item->FindData.ftLastWriteTime); lstrcpy(Info->Description, lpszPtr); return GETARC_SUCCESS; @@ -299,9 +301,9 @@ struct DirInfo nSkipLen = nStrLen; else { - lstrcpyn(Prefix, Buf+nSkipLen+(Buf[nSkipLen]=='\\'?1:0), ARRAYSIZE(Prefix)-2); + lstrcpyn(Prefix, Buf + nSkipLen + (Buf[nSkipLen] == '\\' ? 1 : 0), ARRAYSIZE(Prefix) - 2); nPrefixLen = lstrlen(Prefix); - if (nPrefixLen && Prefix[nPrefixLen-1] != '\\') + if (nPrefixLen && Prefix[nPrefixLen - 1] != '\\') { Prefix[nPrefixLen++] = '\\'; Prefix[nPrefixLen] = 0; @@ -319,16 +321,16 @@ struct DirInfo continue; } - if ( (nStrLen==NAME_DISP+1 && *(Buf+NAME_DISP)=='.') || - (nStrLen==NAME_DISP+2 && *(Buf+NAME_DISP+1)=='.') ) + if ((nStrLen == NAME_DISP + 1 && *(Buf + NAME_DISP) == '.') || + (nStrLen == NAME_DISP + 2 && *(Buf + NAME_DISP + 1) == '.')) continue; if (Compare(Buf, DirEndHeader[0]) || Compare(Buf, DirEndHeader[1])) { - nSkipLen=0; *Prefix=0; nPrefixLen = 0; + nSkipLen = 0; *Prefix = 0; nPrefixLen = 0; continue; } //2008-11-30 Смысла нет, если - if (nStrLen>NAME_DISP && *Buf!=' ' && *(Buf+1)!=' ') + if (nStrLen > NAME_DISP && *Buf != ' ' && *(Buf + 1) != ' ') { memset(Item, 0, sizeof(PluginPanelItem)); @@ -340,43 +342,70 @@ struct DirInfo if (CP_Check == cp_NonChecked) { //TODO: Проверить, может это UTF8? - int iUtf = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, Buf+NAME_DISP, -1, Utf8, ARRAYSIZE(Utf8)); + const int iUtf = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, Buf, -1, Utf8, ARRAYSIZE(Utf8)); //BUGBUG: ?? OEM ? - int iWide = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, Buf+NAME_DISP, -1, Wide, ARRAYSIZE(Wide)); + const int iWide = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, Buf, -1, Wide, ARRAYSIZE(Wide)); if (iUtf > 0 && iWide > 0 && iUtf < iWide) { CP_Check = cp_UTF8; } } - lstrcpyn(Item->FindData.cFileName+nPrefixLen, Buf+NAME_DISP, ARRAYSIZE(Item->FindData.cFileName)-nPrefixLen); - if (Compare(Buf+ID_DIR_DISP, DirID) || Compare(Buf+ID_DIR_DISP, JunID)) - Item->FindData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY; + bool copied = false; + const int cchMaxLen = ARRAYSIZE(Item->FindData.cFileName) - nPrefixLen; + if (CP_Check == cp_UTF8) + { + const int iUtf = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, Buf, -1, Utf8, ARRAYSIZE(Utf8)); + if (iUtf > NAME_DISP) { + const int iWide = WideCharToMultiByte(CP_UTF8, 0, Utf8 + NAME_DISP, -1, + Item->FindData.cFileName + nPrefixLen, cchMaxLen, nullptr, nullptr); + copied = (iWide > 0 && iWide < cchMaxLen); + } + } + if (!copied) + { + lstrcpyn(Item->FindData.cFileName + nPrefixLen, Buf + NAME_DISP, cchMaxLen); + } + + switch (CP_Check) + { + case cp_ANSI: + Item->UserData = CP_ACP; break; + case cp_OEM: + Item->UserData = CP_OEMCP; break; + case cp_UTF8: + Item->UserData = CP_UTF8; break; + default: + Item->UserData = 0; + } + + if (Compare(Buf + ID_DIR_DISP, DirID) || Compare(Buf + ID_DIR_DISP, JunID)) + Item->FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; else { FARINT64 nFileSize; - nFileSize.i64=AtoI(Buf+SIZE_DISP, 16); - Item->FindData.nFileSizeLow=nFileSize.Part.LowPart; - Item->FindData.nFileSizeHigh=nFileSize.Part.HighPart; + nFileSize.i64 = AtoI(Buf + SIZE_DISP, 16); + Item->FindData.nFileSizeLow = nFileSize.Part.LowPart; + Item->FindData.nFileSizeHigh = nFileSize.Part.HighPart; } SYSTEMTIME st; - st.wDayOfWeek=st.wSecond=st.wMilliseconds=0; - st.wDay=(WORD)AtoI(Buf+DATA_DISP, 2); - st.wMonth=(WORD)AtoI(Buf+DATA_DISP+3, 2); - st.wYear=(WORD)AtoI(Buf+DATA_DISP+6, 4); - st.wHour=(WORD)AtoI(Buf+TIME_DISP, 2); - st.wMinute=(WORD)AtoI(Buf+TIME_DISP+3, 2); + st.wDayOfWeek = st.wSecond = st.wMilliseconds = 0; + st.wDay = (WORD)AtoI(Buf + DATA_DISP, 2); + st.wMonth = (WORD)AtoI(Buf + DATA_DISP + 3, 2); + st.wYear = (WORD)AtoI(Buf + DATA_DISP + 6, 4); + st.wHour = (WORD)AtoI(Buf + TIME_DISP, 2); + st.wMinute = (WORD)AtoI(Buf + TIME_DISP + 3, 2); //st.wYear+=st.wYear<50?2000:1900; FILETIME ft; - SystemTimeToFileTime(&st,&ft); - LocalFileTimeToFileTime(&ft,&Item->FindData.ftLastWriteTime); + SystemTimeToFileTime(&st, &ft); + LocalFileTimeToFileTime(&ft, &Item->FindData.ftLastWriteTime); //lstrcpy(Info->Description, Descrip); -- Maks поставить VolumeID в Description - char *Temp = Pos; //дурацкая поддержка описаний внутри DIR файла - if(GetS(Buf, 4095)) - if(Compare(Buf, " @")) - lstrcpyn(Info->Description, Buf+2, 256); + char* Temp = Pos; //дурацкая поддержка описаний внутри DIR файла + if (GetS(Buf, 4095)) + if (Compare(Buf, " @")) + lstrcpyn(Info->Description, Buf + 2, 256); else Pos = Temp; @@ -384,66 +413,69 @@ struct DirInfo } } return GETARC_EOF; - }; + } BOOL closeArchive() { if (Data) UnmapViewOfFile(Data); - Data = NULL; + Data = nullptr; if (MapHandle && (MapHandle != INVALID_HANDLE_VALUE)) CloseHandle(MapHandle); - MapHandle = NULL; + MapHandle = nullptr; if (Handle && (Handle != INVALID_HANDLE_VALUE)) CloseHandle(Handle); - Handle = NULL; + Handle = nullptr; DirInfo* p = this; if (p == gpCur) - gpCur = NULL; + gpCur = nullptr; free(p); return true; - }; + } }; -BOOL WINAPI _export IsArchive(char *Name, const unsigned char *Data, int DataSize) +BOOL WINAPI _export IsArchive(char* Name, const unsigned char* Data, int DataSize) { - _ASSERTE(gpCur!=NULL); - static const char *ID[]={ " Том в устройстве ", " Volume in drive ", "Queued to drive " }; - BOOL lbRc = - gpCur->Compare((char *)Data, ID[0], true, min(lstrlen(ID[0]), DataSize)) || - gpCur->Compare((char *)Data, ID[1], false, min(lstrlen(ID[1]), DataSize)) || - gpCur->Compare((char *)Data, ID[2], false, min(lstrlen(ID[2]), DataSize)) ; + _ASSERTE(gpCur != nullptr); + static const char* ID[] = { " Том в устройстве ", " Volume in drive ", "Queued to drive " }; + BOOL lbRc = FALSE; + const char* strData = reinterpret_cast(Data); + for (const auto* id : ID) { + if (gpCur->Compare(strData, id, true, min(lstrlen(id), DataSize))) + { + lbRc = TRUE; + break; + } + + } return lbRc; } -/* -void WINAPI SetFarInfo(const struct PluginStartupInfo *Info) -{ -::Info=*Info; -} -*/ -BOOL WINAPI _export OpenArchive(char *Name, int *Type) + +BOOL WINAPI _export OpenArchive(char* Name, int* Type) { - _ASSERTE(gpCur==NULL); - gpCur = (DirInfo*)calloc(1,sizeof(DirInfo)); - gpCur->Handle=CreateFile(Name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, - FILE_FLAG_SEQUENTIAL_SCAN, NULL); + _ASSERTE(gpCur == nullptr); + gpCur = static_cast(calloc(1, sizeof(DirInfo))); + if (!gpCur) + return FALSE; + gpCur->Handle = CreateFile(Name, GENERIC_READ, FILE_SHARE_READ, nullptr, + OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); return gpCur->openArchive(Type); } -int WINAPI _export GetArcItem(struct PluginPanelItem *Item, struct ArcItemInfo *Info) +int WINAPI _export GetArcItem(struct PluginPanelItem* Item, struct ArcItemInfo* Info) { if (!gpCur) return GETARC_EOF; return gpCur->getArcItem(Item, Info); } -BOOL WINAPI _export CloseArchive(struct ArcInfo *Info) +BOOL WINAPI _export CloseArchive(struct ArcInfo* Info) { if (gpCur) { @@ -454,34 +486,34 @@ BOOL WINAPI _export CloseArchive(struct ArcInfo *Info) //??эту функцию надо бы выбросить, чтобы модуль не появлялся в меню MultiArc, //но тогда нарушается работа самого MultiArc :( -BOOL WINAPI _export GetFormatName(int Type, char *FormatName, char *DefaultExt) +BOOL WINAPI _export GetFormatName(int Type, char* FormatName, char* DefaultExt) { - if (Type==0) + if (Type == 0) { lstrcpy(FormatName, "DIR"); - lstrcpy(DefaultExt,"dir"); + lstrcpy(DefaultExt, "dir"); return true; } return false; } -BOOL WINAPI _export GetDefaultCommands(int Type,int Command,char *Dest) +BOOL WINAPI _export GetDefaultCommands(int Type, int Command, char* Dest) { - if (Type==0) + if (Type == 0) { - if (Command==0) + if (Command == 0) { //extract (распаковка) lstrcpyA(Dest, "dir.fmt.exe x %%A %%L"); } - else if (Command==1) + else if (Command == 1) { //extract without path (распаковка без путей) lstrcpyA(Dest, "dir.fmt.exe e %%A %%L"); } else { - *Dest=0; + *Dest = 0; } return true; } @@ -492,16 +524,18 @@ BOOL WINAPI _export GetDefaultCommands(int Type,int Command,char *Dest) int nLastItemIndex = -1; -int MODULE_EXPORT OpenStorage(StorageOpenParams params, HANDLE *storage, StorageGeneralInfo* info) +int MODULE_EXPORT OpenStorage(StorageOpenParams params, HANDLE* storage, StorageGeneralInfo* info) { nLastItemIndex = -1; - gpCur = (DirInfo*)calloc(1,sizeof(DirInfo)); - gpCur->Handle = CreateFileW(params.FilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, - FILE_FLAG_SEQUENTIAL_SCAN, NULL); + gpCur = static_cast(calloc(1, sizeof(DirInfo))); + if (!gpCur) + return SOR_INVALID_FILE; + gpCur->Handle = CreateFileW(params.FilePath, GENERIC_READ, FILE_SHARE_READ, nullptr, + OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); int Type = 0; if (gpCur->openArchive(&Type)) { - *storage = (HANDLE)gpCur; + *storage = static_cast(gpCur); lstrcpyW(info->Format, L"Dir"); lstrcpyW(info->Compression, L""); lstrcpyW(info->Comment, L""); @@ -513,7 +547,7 @@ int MODULE_EXPORT OpenStorage(StorageOpenParams params, HANDLE *storage, Storage void MODULE_EXPORT CloseStorage(HANDLE storage) { - DirInfo* p = (DirInfo*)storage; + DirInfo* p = static_cast(storage); if (p) p->closeArchive(); } @@ -521,22 +555,21 @@ void MODULE_EXPORT CloseStorage(HANDLE storage) int MODULE_EXPORT GetStorageItem(HANDLE storage, int item_index, StorageItemInfo* item_info) { int iRc = GET_ITEM_NOMOREITEMS; - _ASSERTE(item_index>nLastItemIndex); - DirInfo* p = (DirInfo*)storage; + _ASSERTE(item_index > nLastItemIndex); + DirInfo* p = static_cast(storage); nLastItemIndex = item_index; - PluginPanelItem* Item = (PluginPanelItem*)calloc(1,sizeof(PluginPanelItem)); - ArcItemInfo* Info = (ArcItemInfo*)calloc(1,sizeof(ArcItemInfo)); - if (p->getArcItem(Item, Info) == GETARC_SUCCESS) + PluginPanelItem Item{}; + ArcItemInfo Info{}; + if (p->getArcItem(&Item, &Info) == GETARC_SUCCESS) { - item_info->Attributes = Item->FindData.dwFileAttributes; - LARGE_INTEGER li; li.LowPart = Item->FindData.nFileSizeLow; li.HighPart = Item->FindData.nFileSizeHigh; + item_info->Attributes = Item.FindData.dwFileAttributes; + LARGE_INTEGER li; li.LowPart = Item.FindData.nFileSizeLow; li.HighPart = Item.FindData.nFileSizeHigh; item_info->Size = li.QuadPart; - item_info->CreationTime = Item->FindData.ftLastWriteTime; - item_info->ModificationTime = Item->FindData.ftLastWriteTime; - MultiByteToWideChar((p->CP_Check == p->cp_UTF8) ? CP_UTF8 : CP_OEMCP, 0, Item->FindData.cFileName, -1, item_info->Path, ARRAYSIZE(item_info->Path)); + item_info->CreationTime = Item.FindData.ftLastWriteTime; + item_info->ModificationTime = Item.FindData.ftLastWriteTime; + MultiByteToWideChar((p->CP_Check == p->cp_UTF8) ? CP_UTF8 : CP_OEMCP, 0, Item.FindData.cFileName, -1, item_info->Path, ARRAYSIZE(item_info->Path)); iRc = GET_ITEM_OK; } - free(Item); free(Info); return iRc; } diff --git a/Dir_b3/dir_b3.rc b/Dir_b3/dir_b3.rc index 2413d33..daffc9f 100644 --- a/Dir_b3/dir_b3.rc +++ b/Dir_b3/dir_b3.rc @@ -1,98 +1,96 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// German (Germany) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) -LANGUAGE LANG_GERMAN, SUBLANG_GERMAN -#pragma code_page(1252) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winres.h""\r\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,0,0,6 - PRODUCTVERSION 1,71,0,0 - FILEFLAGSMASK 0x0L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004e4" - BEGIN - VALUE "Comments", "Current developer: ConEmu.Maximus5@gmail.com" - VALUE "FileDescription", "DIR XP/2003/Vista/7 parse for FAR Manager" - VALUE "FileVersion", "3.0 build 6" - VALUE "InternalName", "Dir" - VALUE "LegalCopyright", "© Alexander Arefiev 2001, © Maximus5 2012" - VALUE "OriginalFilename", "dir.so" - VALUE "ProductName", "FAR Manager" - VALUE "ProductVersion", "1.71" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1252 - END -END - -#endif // German (Germany) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +// Microsoft Visual C++ generated resource script. +// +#include "resource." + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// German (Germany) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) +LANGUAGE LANG_GERMAN, SUBLANG_GERMAN +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 3,0,0,7 + PRODUCTVERSION 1,71,0,0 + FILEFLAGSMASK 0x0L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004e4" + BEGIN + VALUE "Comments", "Current developer: ConEmu.Maximus5@gmail.com" + VALUE "FileDescription", "DIR XP/2003/Vista/7 parse for FAR Manager" + VALUE "FileVersion", "3.0 build 7" + VALUE "InternalName", "Dir" + VALUE "LegalCopyright", "© Alexander Arefiev 2001, © Maximus5 2012" + VALUE "OriginalFilename", "dir.so" + VALUE "ProductName", "FAR Manager" + VALUE "ProductVersion", "1.71" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1252 + END +END + +#endif // German (Germany) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Dir_b3/dir_so.vcxproj b/Dir_b3/dir_so.vcxproj index e003a1f..8ba4efa 100644 --- a/Dir_b3/dir_so.vcxproj +++ b/Dir_b3/dir_so.vcxproj @@ -23,6 +23,7 @@ + @@ -175,6 +176,7 @@ true false dir_b3.def + C:\Users\Maksim.Moisiuk\AppData\Local\Far Manager x64\Plugins\Observer\modules\dir64.so diff --git a/Dir_b3/dir_so.vcxproj.filters b/Dir_b3/dir_so.vcxproj.filters index d4aec48..3598203 100644 --- a/Dir_b3/dir_so.vcxproj.filters +++ b/Dir_b3/dir_so.vcxproj.filters @@ -23,6 +23,10 @@ Source Files + + + Resource Files + diff --git a/Dir_b3/resource.h b/Dir_b3/resource.h index 4ca2fd3..8b17bc2 100644 --- a/Dir_b3/resource.h +++ b/Dir_b3/resource.h @@ -1,6 +1,7 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by dir_b3.rc +// // Next default values for new objects //