Skip to content

Commit

Permalink
Use system wildcards for filter extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyhamster committed Jun 30, 2011
1 parent 0da60f1 commit 5919b2c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/plugin/FarStorage.cpp
Expand Up @@ -111,7 +111,7 @@ int StorageObject::ReadFileList(bool &aborted)
__int64 nTotalSize = 0;
DWORD nNumFiles = 0, nNumDirs = 0;

ExternalModule &module = m_pModules->modules[m_nModuleIndex];
const ExternalModule &module = m_pModules->GetModule(m_nModuleIndex);

DWORD item_index = 0;
StorageItemInfo item_info;
Expand Down Expand Up @@ -185,7 +185,7 @@ int StorageObject::ReadFileList(bool &aborted)

int StorageObject::Extract( ExtractOperationParams &params )
{
return m_pModules->modules[m_nModuleIndex].Extract(m_pStoragePtr, params);
return m_pModules->GetModule(m_nModuleIndex).Extract(m_pStoragePtr, params);
}

int StorageObject::ChangeCurrentDir( const wchar_t* path )
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/FarStorage.h
Expand Up @@ -45,7 +45,7 @@ class StorageObject
ContentTreeNode* GetItem(size_t index);

ContentTreeNode* CurrentDir() const { return m_pCurrentDir; }
const wchar_t* GetModuleName() const { return (m_nModuleIndex >= 0) ? m_pModules->modules[m_nModuleIndex].ModuleName : NULL; }
const wchar_t* GetModuleName() const { return (m_nModuleIndex >= 0) ? m_pModules->GetModule(m_nModuleIndex).Name() : NULL; }
const wchar_t* StoragePath() const { return m_wszStoragePath; }
__int64 TotalSize() const { return m_nTotalSize; }
int NumFiles() const { return m_nNumFiles; }
Expand Down
79 changes: 43 additions & 36 deletions src/plugin/ModulesController.cpp
Expand Up @@ -4,6 +4,41 @@

#define SECTION_BUF_SIZE 1024

static bool DoesExtensionFilterMatch( const wchar_t* path, const vector<wstring> &filter )
{
if (filter.size() == 0)
return true;

for (size_t i = 0; i < filter.size(); i++)
{
if (PathMatchSpec(path, filter[i].c_str()))
return true;
}

return false;
}

static void ParseExtensionList(const wchar_t* listval, ExternalModule& module)
{
if (!listval || !listval[0]) return;

wchar_t* context = NULL;
wchar_t* strList = _wcsdup(listval);

wchar_t* token = wcstok_s(strList, L";", &context);
while (token)
{
if (wcslen(token) > 0)
{
while(!token[0]) token++;
module.ExtensionFilter.push_back(token);
}

token = wcstok_s(NULL, L";", &context);
}
free(strList);
}

int ModulesController::Init( const wchar_t* basePath, const wchar_t* configPath )
{
Cleanup();
Expand All @@ -21,21 +56,20 @@ int ModulesController::Init( const wchar_t* basePath, const wchar_t* configPath
{
OptionsItem nextOpt = mModulesList->GetOption(i);

ExternalModule module = {0};
wcscpy_s(module.ModuleName, ARRAY_SIZE(module.ModuleName), nextOpt.key);
wcscpy_s(module.LibraryFile, ARRAY_SIZE(module.LibraryFile), nextOpt.value);
ExternalModule module(nextOpt.key, nextOpt.value);

// Get module specific settings section
memset(wszModuleSection, 0, sizeof(wszModuleSection));
optFile.GetSectionLines(module.ModuleName, wszModuleSection, SECTION_BUF_SIZE);
optFile.GetSectionLines(module.Name(), wszModuleSection, SECTION_BUF_SIZE);

if (LoadModule(basePath, module, wszModuleSection))
{
// Read extensions filter for each module
if (mFiltersList != NULL)
{
mFiltersList->GetValue(module.ModuleName, module.ExtensionFilter, ARRAY_SIZE(module.ExtensionFilter));
_wcsupr_s(module.ExtensionFilter);
wchar_t extList[OPT_VAL_MAXLEN] = {0};
mFiltersList->GetValue(module.Name(), extList, ARRAY_SIZE(extList));
ParseExtensionList(extList, module);
}

modules.push_back(module);
Expand Down Expand Up @@ -101,11 +135,11 @@ void ModulesController::CloseStorageFile(int moduleIndex, HANDLE storage)

bool ModulesController::LoadModule( const wchar_t* basePath, ExternalModule &module, const wchar_t* moduleSettings )
{
if (!module.ModuleName[0] || !module.LibraryFile[0])
if (!module.Name()[0] || !module.LibraryFile()[0])
return false;

wchar_t wszFullModulePath[MAX_PATH] = {0};
swprintf_s(wszFullModulePath, MAX_PATH, L"%s%s", basePath, module.LibraryFile);
swprintf_s(wszFullModulePath, MAX_PATH, L"%s%s", basePath, module.LibraryFile());

module.ModuleHandle = LoadLibraryEx(wszFullModulePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (module.ModuleHandle != NULL)
Expand Down Expand Up @@ -143,37 +177,10 @@ bool ModulesController::LoadModule( const wchar_t* basePath, ExternalModule &mod
DWORD err = GetLastError();

wchar_t msgText[200] = {0};
swprintf_s(msgText, ARRAY_SIZE(msgText), L"Can not load modules (Error: %d, Path: %s)", err, module.LibraryFile);
swprintf_s(msgText, ARRAY_SIZE(msgText), L"Can not load modules (Error: %d, Path: %s)", err, module.LibraryFile());
MessageBox(0, msgText, L"Error", MB_OK);
}
#endif

return false;
}

bool ModulesController::DoesExtensionFilterMatch( const wchar_t* path, const wchar_t* filter )
{
if (!filter || !*filter)
return true;

const wchar_t* extPtr = wcsrchr(path, '.');
if (extPtr != NULL && wcschr(extPtr, '\\') == NULL)
{
bool result = false;

wchar_t* extStr = _wcsdup(extPtr);
_wcsupr_s(extStr, wcslen(extStr)+1);

const wchar_t* posInFilter = wcsstr(filter, extStr);
if (posInFilter != NULL)
{
size_t extLen = wcslen(extStr);
result = (posInFilter[extLen] == 0) || (posInFilter[extLen] == ';');
}

free(extStr);
return result;
}

return false;
}
31 changes: 24 additions & 7 deletions src/plugin/ModulesController.h
Expand Up @@ -5,10 +5,19 @@

struct ExternalModule
{
wchar_t ModuleName[32];
wchar_t LibraryFile[32];
ExternalModule(const wchar_t* Name, const wchar_t* Library)
: m_sModuleName(Name), m_sLibraryFile(Library), ModuleHandle(0), ModuleVersion(0)
{
LoadModule = NULL;
UnloadModule = NULL;
OpenStorage = NULL;
CloseStorage = NULL;
GetNextItem = NULL;
Extract = NULL;
}

HMODULE ModuleHandle;
wchar_t ExtensionFilter[128];
std::vector<wstring> ExtensionFilter;

LoadSubModuleFunc LoadModule;
UnloadSubModuleFunc UnloadModule;
Expand All @@ -18,6 +27,13 @@ struct ExternalModule
CloseStorageFunc CloseStorage;
GetItemFunc GetNextItem;
ExtractFunc Extract;

const wchar_t* Name() const { return m_sModuleName.c_str(); }
const wchar_t* LibraryFile() const { return m_sLibraryFile.c_str(); }

private:
std::wstring m_sModuleName;
std::wstring m_sLibraryFile;
};

struct OpenStorageFileInParams
Expand All @@ -31,18 +47,19 @@ struct OpenStorageFileInParams
class ModulesController
{
private:
vector<ExternalModule> modules;

bool LoadModule(const wchar_t* basePath, ExternalModule &module, const wchar_t* moduleSettings);
bool DoesExtensionFilterMatch(const wchar_t* path, const wchar_t* filter);

public:
vector<ExternalModule> modules;

ModulesController(void) {};
~ModulesController(void) { this->Cleanup(); };

int Init(const wchar_t* basePath, const wchar_t* configPath);
void Cleanup();
size_t NumModules() { return modules.size(); };

size_t NumModules() { return modules.size(); }
const ExternalModule& GetModule(int index) { return modules[index]; }

int OpenStorageFile(OpenStorageFileInParams srcParams, int *moduleIndex, HANDLE *storage, StorageGeneralInfo *info);
void CloseStorageFile(int moduleIndex, HANDLE storage);
Expand Down
8 changes: 8 additions & 0 deletions src/plugin/Observer.vcproj
Expand Up @@ -77,6 +77,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="2"
GenerateManifest="false"
Expand Down Expand Up @@ -165,6 +166,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="2"
GenerateManifest="false"
Expand Down Expand Up @@ -253,6 +255,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="1"
ModuleDefinitionFile="Observer.def"
Expand Down Expand Up @@ -343,6 +346,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="1"
ModuleDefinitionFile="Observer.def"
Expand Down Expand Up @@ -431,6 +435,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="2"
GenerateManifest="false"
Expand Down Expand Up @@ -519,6 +524,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="2"
GenerateManifest="false"
Expand Down Expand Up @@ -607,6 +613,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="1"
ModuleDefinitionFile="ObserverUni.def"
Expand Down Expand Up @@ -697,6 +704,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib"
OutputFile="$(OutDir)\4Observer.dll"
LinkIncremental="1"
ModuleDefinitionFile="ObserverUni.def"
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/ObserverUni.cpp
Expand Up @@ -189,14 +189,14 @@ static bool DlgHlp_GetEditBoxText(HANDLE hDlg, int ctrlIndex, wchar_t* buf, size

static int SelectModuleToOpenFileAs()
{
size_t nNumModules = g_pController.modules.size();
size_t nNumModules = g_pController.NumModules();

FarMenuItem* MenuItems = new FarMenuItem[nNumModules];
memset(MenuItems, 0, nNumModules * sizeof(FarMenuItem));
for (size_t i = 0; i < nNumModules; i++)
{
const ExternalModule& modInfo = g_pController.modules[i];
MenuItems[i].Text = modInfo.ModuleName;
const ExternalModule& modInfo = g_pController.GetModule(i);
MenuItems[i].Text = modInfo.Name();
}

int nMSel = FarSInfo.Menu(FarSInfo.ModuleNumber, -1, -1, 0, 0, GetLocMsg(MSG_OPEN_SELECT_MODULE), NULL, NULL, NULL, NULL, MenuItems, (int) nNumModules);
Expand Down
1 change: 1 addition & 0 deletions src/plugin/stdafx.h
Expand Up @@ -15,6 +15,7 @@
// Additional headers
#include <wchar.h>
#include <ShlObj.h>
#include <Shlwapi.h>

// STL
#include <string>
Expand Down
18 changes: 9 additions & 9 deletions src/plugin/text/observer.ini
Expand Up @@ -15,20 +15,20 @@ VDISK=modules\vdisk.so
MPQ=modules\mpq.so

[Filters]
MSI=.msi;.msm
NSIS=.exe
WISE=.exe
VP=.vp
RELIC=.big;.sga
PST=.pst
VALVE=.bsp;.gcf;.vbsp;.vpk;.pak;.xzp;.wad
MSI=*.msi;*.msm
NSIS=*.exe
WISE=*.exe
VP=*.vp
RELIC=*.big;*.sga
PST=*.pst
VALVE=*.bsp;*.gcf;*.vbsp;*.vpk;*.pak;*.xzp;*.wad
UDF=
ISO=
X-CAT=.cat;.pck;.pbd;.pbb
X-CAT=*.cat;*.pck;*.pbd;*.pbb
MBOX=
MIME=
VDISK=
MPQ=.mpq;.exe;.S2MA;.SC2Data;.SC2Map;.SC2Mod;.SC2Assets;.SC2Archive;.mpqe
MPQ=*.mpq;*.exe;*.S2MA;*.SC2Data;*.SC2Map;*.SC2Mod;*.SC2Assets;*.SC2Archive;*.mpqe

[General]
PanelHeaderPrefix=
Expand Down
1 change: 1 addition & 0 deletions src/plugin/text/whatsnew.txt
Expand Up @@ -3,6 +3,7 @@ Changes history:
1.8.0
- Added support for files in Mbox format.
- Replaced MIME module. It should be faster and more standard compliant.
- Now standard wildcards are used in filter extensions.
- VALVE: Fixed signature detection for VPK files.
- VALVE: Fixed possible crash on some VBSP files.
- MSI: File {msi_info.txt} have creation/modification date from package info.
Expand Down
1 change: 1 addition & 0 deletions src/plugin/text/whatsnew_ru.txt
Expand Up @@ -3,6 +3,7 @@
1.8.0
- ��������� ��������� ��� ������ ������� Mbox.
- ������� ������ MIME. ��������� �������� ������ � ������������� �� ����������.
- ������ ��� �������� ���������� ������������ ����������� �����.
- VALVE: ���������� ����������� ��������� ��� VPK ������.
- VALVE: ���������� ������� �� ��������� VBSP ������.
- MSI: ���� {msi_info}.txt ����� ���� ��������/����������� �� ���������� ������.
Expand Down

0 comments on commit 5919b2c

Please sign in to comment.