Skip to content

Commit

Permalink
v1.1.5.7
Browse files Browse the repository at this point in the history
- fixed TA exe path detection, now regardless of "restart TA" option
- fixed mistakenly restarting TA when its process is alreadt running but without window yet
  • Loading branch information
setsumi committed Jan 21, 2019
1 parent 4e2f3f3 commit 531a566
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 51 deletions.
42 changes: 21 additions & 21 deletions TAHelper2009/TAHelper.cbproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,40 @@
<BCC_OptimizeForSize>true</BCC_OptimizeForSize>
</PropertyGroup>
<ItemGroup>
<CppCompile Include="TAHelper.cpp">
<BuildOrder>-1</BuildOrder>
<BuildOrder>0</BuildOrder>
</CppCompile>
<ResFiles Include="TAHelper.res">
<BuildOrder>-1</BuildOrder>
<BuildOrder>1</BuildOrder>
</ResFiles>
<CppCompile Include="WindowUtils.cpp">
<DependentOn>WindowUtils.h</DependentOn>
<BuildOrder>7</BuildOrder>
</CppCompile>
<CppCompile Include="Wakan.cpp">
<DependentOn>Wakan.h</DependentOn>
<BuildOrder>6</BuildOrder>
</CppCompile>
<None Include="ModelSupport_TAHelper\default.txvpck"/>
<None Include="ModelSupport_TAHelper\default.txaPackage"/>
<CppCompile Include="Unit1.cpp">
<BuildOrder>2</BuildOrder>
<Form>FormTAHelper</Form>
<DependentOn>Unit1.h</DependentOn>
<BuildOrder>0</BuildOrder>
</CppCompile>
<None Include="ModelSupport_TAHelper\default.txaPackage"/>
<CppCompile Include="UnitOSD.cpp">
<Form>FormOSD</Form>
<DependentOn>UnitOSD.h</DependentOn>
<BuildOrder>5</BuildOrder>
</CppCompile>
<None Include="changelog.txt"/>
<CppCompile Include="..\TAHplugin\StringUtils.cpp">
<DependentOn>..\TAHplugin\StringUtils.h</DependentOn>
<BuildOrder>8</BuildOrder>
</CppCompile>
<ResFiles Include="TAHelper.res">
<BuildOrder>-1</BuildOrder>
<BuildOrder>1</BuildOrder>
</ResFiles>
<CppCompile Include="TAHelper.cpp">
<BuildOrder>-1</BuildOrder>
<BuildOrder>0</BuildOrder>
</CppCompile>
<CppCompile Include="WindowUtils.cpp">
<DependentOn>WindowUtils.h</DependentOn>
<BuildOrder>7</BuildOrder>
</CppCompile>
<None Include="ModelSupport_TAHelper\default.txvpck"/>
<CppCompile Include="Wakan.cpp">
<DependentOn>Wakan.h</DependentOn>
<BuildOrder>6</BuildOrder>
</CppCompile>
<None Include="changelog.txt"/>
<FormResources Include="Unit1.dfm"/>
<FormResources Include="UnitOSD.dfm"/>
<BuildConfiguration Include="Base">
Expand All @@ -137,7 +137,7 @@
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">1</VersionInfo>
<VersionInfo Name="Release">5</VersionInfo>
<VersionInfo Name="Build">6</VersionInfo>
<VersionInfo Name="Build">7</VersionInfo>
<VersionInfo Name="Debug">True</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
Expand All @@ -149,7 +149,7 @@
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription">TAHelper by furniture</VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.1.5.6</VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.1.5.7</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
Expand Down
Binary file modified TAHelper2009/TAHelper.res
Binary file not shown.
90 changes: 61 additions & 29 deletions TAHelper2009/Unit1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,47 +1545,79 @@ HWND TFormTAHelper::TALFind(bool forcefind, bool notimer)
HWND hw0 = (HWND)LabelTALstatus->Tag; // old value
HWND hw = FindWindow(TA_WCLASS, NULL);
if (hw != NULL) hw = GetAncestor(hw, GA_ROOT); // new value
if (hw != NULL && hw != hw0) RefreshClipboardMonitor();
if (hw != NULL && hw != hw0) {
RefreshClipboardMonitor();
// store TA exe path
DWORD processID = 0;
HANDLE processHandle = NULL;
TCHAR filename[MAX_PATH];
if (GetWindowThreadProcessId(hw, &processID)) {
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, processID);
if (processHandle != NULL) {
if (GetModuleFileNameEx(processHandle, NULL, filename, MAX_PATH)) {
m_TAexe = filename;
}
CloseHandle(processHandle);
}
}
}
if (forcefind || hw != hw0) TALResult(hw); // assign and display result

// monitor TA
if (CheckBoxTARestartOnHang->Checked) {
if (hw == NULL) {
if (!m_TAexe.IsEmpty()) { // restart on termination
UnicodeString tadir(ExtractFilePath(m_TAexe));
tadir = tadir.Delete(tadir.Length(), 1); // remove last separator
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (CreateProcess(m_TAexe.c_str(), NULL, NULL, NULL, FALSE, 0, NULL,
tadir.c_str(), &si, &pi)) {
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
if (hw == NULL) { // restart TA on termination
if (!m_TAexe.IsEmpty()) {
// but check for running process first (compiling dictionaries while no window yet)
bool tarunning = false;
HANDLE hProcSnap = NULL;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);

hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcSnap == INVALID_HANDLE_VALUE) {
throw Exception(L"TFormTAHelper::TALFind() : CreateToolhelp32Snapshot() failed");
}
}
} else {
if (IsHungAppWindow(hw)) { // terminate TA if hung
TerminateProcess(hw);
} else {
// store TA exe path
if (hw != hw0) {
DWORD processID = 0;
if (!Process32First(hProcSnap, &pe32)) {
CloseHandle(hProcSnap);
throw Exception(L"TFormTAHelper::TALFind() : Process32First() failed");
}
do {
// get full exe path
HANDLE processHandle = NULL;
TCHAR filename[MAX_PATH];

if (GetWindowThreadProcessId(hw, &processID)) {
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, processID);
if (processHandle != NULL) {
if (GetModuleFileNameEx(processHandle, NULL, filename, MAX_PATH)) {
m_TAexe = filename;
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, pe32.th32ProcessID);
if (processHandle != NULL) {
if (GetModuleFileNameEx(processHandle, NULL, filename, MAX_PATH)) {
if (m_TAexe.CompareIC(filename) == 0) {
tarunning = true;
CloseHandle(processHandle);
break;
}
CloseHandle(processHandle);
}
CloseHandle(processHandle);
}
} while (Process32Next(hProcSnap, &pe32));
CloseHandle(hProcSnap);

if (!tarunning) { // launch TA process
UnicodeString tadir(ExtractFilePath(m_TAexe));
tadir = tadir.Delete(tadir.Length(), 1); // remove last separator
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (CreateProcess(m_TAexe.c_str(), NULL, NULL, NULL, FALSE, 0, NULL,
tadir.c_str(), &si, &pi)) {
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
}
}
} else {
if (IsHungAppWindow(hw)) { // terminate TA window if hung
TerminateProcess(hw);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion TAHelper2009/Unit1.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ object FormTAHelper: TFormTAHelper
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ItemHeight = 0
ItemHeight = 13
ParentFont = False
ParentShowHint = False
ShowHint = False
Expand Down

0 comments on commit 531a566

Please sign in to comment.