Skip to content

Commit

Permalink
Fixing issue with Galaxy Camras and DLL searchpath
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai committed Sep 28, 2022
1 parent 854b06f commit 69d13eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
30 changes: 20 additions & 10 deletions imswitch/imcommon/controller/CheckUpdatesController.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import urllib.request
import threading
import datetime

import imswitch
from imswitch.imcommon.framework import Signal, Thread
Expand Down Expand Up @@ -72,20 +73,26 @@ def run(self):
downloadURL = releaseResponse.json()['assets'][0]['browser_download_url']
self.__logger.debug("We are downloading the software from: "+downloadURL)

## inplace replacement won't work I guess?
## inplace replacement won't work I guess? => seems to work
def dlImSwitch(downloadURL, fileName):
resultDL = urllib.request.urlretrieve(downloadURL, fileName)

self.sigNewVersionShowInfo.emit("Downloading and updating latest version...")


ImSwitchExeFilename = "ImSwitch.exe"
if os.path.isfile(ImSwitchExeFilename):
self.__logger.debug("Renaming old ImSwitch.exe file")
os.rename(ImSwitchExeFilename, ImSwitchExeFilename+"_BAK")
mThread = threading.Thread(target=dlImSwitch, args=(downloadURL, ImSwitchExeFilename))
mThread = threading.Thread(target=dlImSwitch, args=(downloadURL, ImSwitchExeFilename+"*"))
mThread.start()
mThread.join()

# make a backup copy of the file
if os.path.isfile(ImSwitchExeFilename):
self.__logger.debug("Renaming old ImSwitch.exe file")
tz = datetime.timezone.utc
ft = "%Y-%m-%dT%H:%M:%S%z"
tt = datetime.datetime.now(tz=tz).strftime(ft)
os.rename(ImSwitchExeFilename, ImSwitchExeFilename+"_BAK_"+tt)

# finally rename the downloaded file too
os.rename(ImSwitchExeFilename+"*", ImSwitchExeFilename)

self.__logger.debug("Download successful!")
self.sigNewVersionShowInfo.emit("Download successful! Please restart ImSwitch. ")

Expand All @@ -104,9 +111,12 @@ def dlImSwitch(downloadURL, fileName):
self.sigNoUpdate.emit()


except Exception:
except Exception as e:
self.__logger.warning(traceback.format_exc())
self.sigFailed.emit()
#self.sigFailed.emit()
self.sigNewVersionShowInfo.emit("Updating failed. "+str(e))



def getCurrentCommitDate(self):
return str(subprocess.check_output(['git', 'log', '-n', '1', '--pretty=tformat:%h-%ad', '--date=short']).strip()).split("-")[-3:]
Expand Down
5 changes: 2 additions & 3 deletions imswitch/imcontrol/model/interfaces/gxipy/gxwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
try:
import os
os.add_dll_directory("C:\\Program Files\\Daheng Imaging\\GalaxySDK\\APIDll\\Win64\\")
dll = WinDLL('GxIAPI.dll')
#dll = WinDLL("C:\\Program Files\\Daheng Imaging\\GalaxySDK\\APIDll\\Win64\\GxIAPI.dll")

dll = WinDLL('GxIAPI.dll', winmode=0) # https://stackoverflow.com/questions/59330863/cant-import-dll-module-in-python

except OSError:
print('Cannot find GxIAPI.dll.')
else:
Expand Down

0 comments on commit 69d13eb

Please sign in to comment.