Skip to content

Commit fe1cdfc

Browse files
committed
custom filetype for extensions
1 parent f6742de commit fe1cdfc

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

GUI/extenwindow.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ namespace
3333

3434
bool Load(QString extenName)
3535
{
36-
// Extension is dll and exports "OnNewSentence"
37-
if (QTextFile(extenName + ".dll", QIODevice::ReadOnly).readAll().contains("OnNewSentence"))
36+
if (extenName.endsWith(".dll")) extenName.chop(4);
37+
if (extenName.endsWith(".xdll")) extenName.chop(5);
38+
if (!QFile::exists(extenName + ".xdll")) QFile::copy(extenName + ".dll", extenName + ".xdll");
39+
// Extension must export "OnNewSentence"
40+
if (QTextFile(extenName + ".xdll", QIODevice::ReadOnly).readAll().contains("OnNewSentence"))
3841
{
39-
if (HMODULE module = LoadLibraryW(S(extenName + ".dll").c_str()))
42+
if (HMODULE module = LoadLibraryW(S(extenName + ".xdll").c_str()))
4043
{
4144
if (auto callback = (decltype(Extension::callback))GetProcAddress(module, "OnNewSentence"))
4245
{
@@ -53,7 +56,7 @@ namespace
5356
void Unload(int index)
5457
{
5558
std::scoped_lock writeLock(extenMutex);
56-
FreeLibrary(GetModuleHandleW((extensions.at(index).name + L".dll").c_str()));
59+
FreeLibrary(GetModuleHandleW((extensions.at(index).name + L".xdll").c_str()));
5760
extensions.erase(extensions.begin() + index);
5861
}
5962

@@ -80,14 +83,14 @@ namespace
8083

8184
void Add(QFileInfo extenFile)
8285
{
83-
if (extenFile.suffix() == "dll")
86+
if (extenFile.suffix() == "dll" || extenFile.suffix() == "xdll")
8487
{
8588
if (extenFile.absolutePath() != QDir::currentPath())
8689
{
8790
if (QFile::exists(extenFile.fileName()) && QMessageBox::question(This, EXTENSIONS, CONFIRM_EXTENSION_OVERWRITE) == QMessageBox::Yes) QFile::remove(extenFile.fileName());
8891
if (!QFile::copy(extenFile.absoluteFilePath(), extenFile.fileName())) QMessageBox::warning(This, EXTENSIONS, EXTENSION_WRITE_ERROR);
8992
}
90-
if (Load(extenFile.completeBaseName())) return Sync();
93+
if (Load(extenFile.fileName())) return Sync();
9194
}
9295
QMessageBox::information(This, EXTENSIONS, QString(INVALID_EXTENSION).arg(extenFile.fileName()));
9396
}
@@ -96,7 +99,7 @@ namespace
9699
{
97100
QAction addExtension(ADD_EXTENSION);
98101
if (QMenu::exec({ &addExtension }, ui.extenList->mapToGlobal(point), nullptr, This))
99-
if (QString extenFile = QFileDialog::getOpenFileName(This, ADD_EXTENSION, ".", EXTENSIONS + QString(" (*.dll)")); !extenFile.isEmpty()) Add(extenFile);
102+
if (QString extenFile = QFileDialog::getOpenFileName(This, ADD_EXTENSION, ".", EXTENSIONS + QString(" (*.xdll)\nLibraries (*.dll)")); !extenFile.isEmpty()) Add(extenFile);
100103
}
101104
}
102105

@@ -115,7 +118,7 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension
115118
void CleanupExtensions()
116119
{
117120
std::scoped_lock writeLock(extenMutex);
118-
for (auto extension : extensions) FreeLibrary(GetModuleHandleW((extension.name + L".dll").c_str()));
121+
for (auto extension : extensions) FreeLibrary(GetModuleHandleW((extension.name + L".xdll").c_str()));
119122
extensions.clear();
120123
}
121124

deploy.ps1

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,30 @@ foreach ($language in @{
3535
foreach ($file in @(
3636
"Textractor.exe",
3737
"TextractorCLI.exe",
38-
"texthook.dll",
39-
"Bing Translate.dll",
40-
"Copy to Clipboard.dll",
41-
"DeepL Translate.dll",
42-
"Extra Newlines.dll",
43-
"Extra Window.dll",
44-
"Google Translate.dll",
45-
"Lua.dll",
46-
"Regex Filter.dll",
47-
"Remove Repeated Characters.dll",
48-
"Remove Repeated Phrases.dll",
49-
"Remove Repeated Phrases 2.dll",
50-
"Remove 30 Repeated Sentences.dll",
51-
"Replacer.dll",
52-
"Thread Linker.dll"
38+
"texthook.dll"
5339
))
5440
{
5541
copy -Force -Recurse -Verbose -Destination "$folder/$arch" -Path "Release_$arch/$file";
5642
}
43+
foreach ($extension in @(
44+
"Bing Translate",
45+
"Copy to Clipboard",
46+
"DeepL Translate",
47+
"Extra Newlines",
48+
"Extra Window",
49+
"Google Translate",
50+
"Lua",
51+
"Regex Filter",
52+
"Remove Repeated Characters",
53+
"Remove Repeated Phrases",
54+
"Remove Repeated Phrases 2",
55+
"Remove 30 Repeated Sentences",
56+
"Replacer",
57+
"Thread Linker"
58+
))
59+
{
60+
copy -Force -Recurse -Verbose -Destination "$folder/$arch/$extension.xdll" -Path "Release_$arch/$extension.dll";
61+
}
5762
}
5863
}
5964

0 commit comments

Comments
 (0)