custom filetype for extensions
This commit is contained in:
parent
f6742de3d5
commit
fe1cdfc947
@ -33,10 +33,13 @@ namespace
|
||||
|
||||
bool Load(QString extenName)
|
||||
{
|
||||
// Extension is dll and exports "OnNewSentence"
|
||||
if (QTextFile(extenName + ".dll", QIODevice::ReadOnly).readAll().contains("OnNewSentence"))
|
||||
if (extenName.endsWith(".dll")) extenName.chop(4);
|
||||
if (extenName.endsWith(".xdll")) extenName.chop(5);
|
||||
if (!QFile::exists(extenName + ".xdll")) QFile::copy(extenName + ".dll", extenName + ".xdll");
|
||||
// Extension must export "OnNewSentence"
|
||||
if (QTextFile(extenName + ".xdll", QIODevice::ReadOnly).readAll().contains("OnNewSentence"))
|
||||
{
|
||||
if (HMODULE module = LoadLibraryW(S(extenName + ".dll").c_str()))
|
||||
if (HMODULE module = LoadLibraryW(S(extenName + ".xdll").c_str()))
|
||||
{
|
||||
if (auto callback = (decltype(Extension::callback))GetProcAddress(module, "OnNewSentence"))
|
||||
{
|
||||
@ -53,7 +56,7 @@ namespace
|
||||
void Unload(int index)
|
||||
{
|
||||
std::scoped_lock writeLock(extenMutex);
|
||||
FreeLibrary(GetModuleHandleW((extensions.at(index).name + L".dll").c_str()));
|
||||
FreeLibrary(GetModuleHandleW((extensions.at(index).name + L".xdll").c_str()));
|
||||
extensions.erase(extensions.begin() + index);
|
||||
}
|
||||
|
||||
@ -80,14 +83,14 @@ namespace
|
||||
|
||||
void Add(QFileInfo extenFile)
|
||||
{
|
||||
if (extenFile.suffix() == "dll")
|
||||
if (extenFile.suffix() == "dll" || extenFile.suffix() == "xdll")
|
||||
{
|
||||
if (extenFile.absolutePath() != QDir::currentPath())
|
||||
{
|
||||
if (QFile::exists(extenFile.fileName()) && QMessageBox::question(This, EXTENSIONS, CONFIRM_EXTENSION_OVERWRITE) == QMessageBox::Yes) QFile::remove(extenFile.fileName());
|
||||
if (!QFile::copy(extenFile.absoluteFilePath(), extenFile.fileName())) QMessageBox::warning(This, EXTENSIONS, EXTENSION_WRITE_ERROR);
|
||||
}
|
||||
if (Load(extenFile.completeBaseName())) return Sync();
|
||||
if (Load(extenFile.fileName())) return Sync();
|
||||
}
|
||||
QMessageBox::information(This, EXTENSIONS, QString(INVALID_EXTENSION).arg(extenFile.fileName()));
|
||||
}
|
||||
@ -96,7 +99,7 @@ namespace
|
||||
{
|
||||
QAction addExtension(ADD_EXTENSION);
|
||||
if (QMenu::exec({ &addExtension }, ui.extenList->mapToGlobal(point), nullptr, This))
|
||||
if (QString extenFile = QFileDialog::getOpenFileName(This, ADD_EXTENSION, ".", EXTENSIONS + QString(" (*.dll)")); !extenFile.isEmpty()) Add(extenFile);
|
||||
if (QString extenFile = QFileDialog::getOpenFileName(This, ADD_EXTENSION, ".", EXTENSIONS + QString(" (*.xdll)\nLibraries (*.dll)")); !extenFile.isEmpty()) Add(extenFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +118,7 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension
|
||||
void CleanupExtensions()
|
||||
{
|
||||
std::scoped_lock writeLock(extenMutex);
|
||||
for (auto extension : extensions) FreeLibrary(GetModuleHandleW((extension.name + L".dll").c_str()));
|
||||
for (auto extension : extensions) FreeLibrary(GetModuleHandleW((extension.name + L".xdll").c_str()));
|
||||
extensions.clear();
|
||||
}
|
||||
|
||||
|
35
deploy.ps1
35
deploy.ps1
@ -35,25 +35,30 @@ foreach ($language in @{
|
||||
foreach ($file in @(
|
||||
"Textractor.exe",
|
||||
"TextractorCLI.exe",
|
||||
"texthook.dll",
|
||||
"Bing Translate.dll",
|
||||
"Copy to Clipboard.dll",
|
||||
"DeepL Translate.dll",
|
||||
"Extra Newlines.dll",
|
||||
"Extra Window.dll",
|
||||
"Google Translate.dll",
|
||||
"Lua.dll",
|
||||
"Regex Filter.dll",
|
||||
"Remove Repeated Characters.dll",
|
||||
"Remove Repeated Phrases.dll",
|
||||
"Remove Repeated Phrases 2.dll",
|
||||
"Remove 30 Repeated Sentences.dll",
|
||||
"Replacer.dll",
|
||||
"Thread Linker.dll"
|
||||
"texthook.dll"
|
||||
))
|
||||
{
|
||||
copy -Force -Recurse -Verbose -Destination "$folder/$arch" -Path "Release_$arch/$file";
|
||||
}
|
||||
foreach ($extension in @(
|
||||
"Bing Translate",
|
||||
"Copy to Clipboard",
|
||||
"DeepL Translate",
|
||||
"Extra Newlines",
|
||||
"Extra Window",
|
||||
"Google Translate",
|
||||
"Lua",
|
||||
"Regex Filter",
|
||||
"Remove Repeated Characters",
|
||||
"Remove Repeated Phrases",
|
||||
"Remove Repeated Phrases 2",
|
||||
"Remove 30 Repeated Sentences",
|
||||
"Replacer",
|
||||
"Thread Linker"
|
||||
))
|
||||
{
|
||||
copy -Force -Recurse -Verbose -Destination "$folder/$arch/$extension.xdll" -Path "Release_$arch/$extension.dll";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user