Skip to content

Commit

Permalink
custom filetype for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Artikash committed Sep 10, 2020
1 parent f6742de commit fe1cdfc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
19 changes: 11 additions & 8 deletions GUI/extenwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand All @@ -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);
}

Expand All @@ -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()));
}
Expand All @@ -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);
}
}

Expand All @@ -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();
}

Expand Down
35 changes: 20 additions & 15 deletions deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}

Expand Down

0 comments on commit fe1cdfc

Please sign in to comment.