external call to update addon

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Hurdet
Power Member
Power Member
Posts: 704
Joined: 2003-05-10, 18:02 UTC

external call to update addon

Post by *Hurdet »

I try to call a addons from a c++ file, do it is possibile?
I get crash with 7zip plugin.

Code: Select all

#include <windows.h>
#include <iostream>

typedef int (__stdcall* PackFilesW_t)(
	const wchar_t* PackedFile, 
	const wchar_t* SubPath, 
	const wchar_t* SrcPath, 
	const wchar_t* AddList, 
	int Flags
);

int main() {
	// Path to the WCX file (Total Commander plugin)
	const wchar_t* wcxPath = L"path\\to\\yourplugin.wcx";

	// Load the DLL (WCX plugin)
	HMODULE hModule = LoadLibraryW(wcxPath);
	if (!hModule) {
		std::wcerr << L"Error: Unable to load the WCX plugin.\n";
		return 1;
	}

	// Get the pointer to the PackFilesW function
	PackFilesW_t PackFilesW = (PackFilesW_t)GetProcAddress(hModule, "PackFilesW");
	if (!PackFilesW) {
		std::wcerr << L"Error: Unable to find the PackFilesW function.\n";
		FreeLibrary(hModule);
		return 1;
	}

	// Function parameters
	const wchar_t* PackedFile = L"output.pack"; // Name of the compressed file
	const wchar_t* SubPath = L"";              // SubPath (empty for root)
	const wchar_t* SrcPath = L"path\\to\\source\\"; // Source folder
	wchar_t AddList[] = L"file1.txt\0file2.txt\0\0"; // File list terminated with double \0
	int Flags = 0;                             // Flags (0 = default)

	// Call the PackFilesW function
	int result = PackFilesW(PackedFile, SubPath, SrcPath, AddList, Flags);

	// Check the result
	if (result == 0) {
		std::wcout << L"Compression completed successfully.\n";
	} else {
		std::wcerr << L"Error during compression, code: " << result << L"\n";
	}

	// Release the DLL
	FreeLibrary(hModule);

	return 0;
}
User avatar
Dalai
Power Member
Power Member
Posts: 9943
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: external call to update addon

Post by *Dalai »

Of course it's possible to use TC plugins outside of TC. Since they're just (renamed) DLLs after all it doesn't matter which program hosts them. However, it's necessary to follow the plugin interface description. Unfortunately I haven't written a packer plugin which can create archives; the closest thing is the packer part of my CertificateInfo plugin with simple extraction capabilities.

My guess is that you need to implement/call the functions listed as mandatory in the WCX interface description. Maybe the plugin calls ProcessDataProc during the pack operation. Probably the easiest thing to see where it crashes is to debug it, i.e. step through your code line by line.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50386
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: external call to update addon

Post by *ghisler(Author) »

1. Try calling SetProcessDataProcW, this sets a callback function to tell the caller about the pack progress. Some plugins seem to expect that the callback function is valid and don't check whether SetProcessDataProcW has been called or not.
2. Make sure that PackedFile and SrcPath are absolute paths (with drive letter or UNC prefix).
3. Call PackSetDefaultParams (there is no Unicode variant) to tell the plugin where to store its settings
4. Call GetPackerCaps to be sure that the plugin supports PK_CAPS_MODIFY to change existing archives, and PK_CAPS_MULTIPLE to add more than one file to a single archive (e.g. GZIP doesn't).
Author of Total Commander
https://www.ghisler.com
Hurdet
Power Member
Power Member
Posts: 704
Joined: 2003-05-10, 18:02 UTC

Re: external call to update addon

Post by *Hurdet »

ty.
Hurdet
Power Member
Power Member
Posts: 704
Joined: 2003-05-10, 18:02 UTC

Re: external call to update addon

Post by *Hurdet »

When I use
HANDLE hArcData = OpenArchiveW(&arcData);
ReadHeaderExW(hArcData, &header)
i'm able to extract from archive without password.
But when it have password 7zip ask for it.
How bypass prompt using pwd from 7z.ini file?
Post Reply