class GameInfoTest(TestCase): def setUp(self): self.dota_info_normal = """ "GameInfo" { game "DOTA 2" gamelogo 1 type multiplayer_only nomodels 1 nohimodel 1 nocrosshair 0 GameData "dota.fgd" SupportsDX8 0 FileSystem { SteamAppId 816 ToolsAppId 211 SearchPaths { Game |gameinfo_path|. Game platform } } }""" self.dota_info_modded = """ "GameInfo" { game "DOTA 2" gamelogo 1 type multiplayer_only nomodels 1 nohimodel 1 nocrosshair 0 GameData "dota.fgd" SupportsDX8 0 FileSystem { SteamAppId 816 ToolsAppId 211 SearchPaths { Game |gameinfo_path|. Game platform Game |gameinfo_path|addons\d2moddin } } }""" new_dota_dir() self.manager = ModManager() # self.real_method = self.manager._dota_path # self.manager._dota_path = Mock(return_value = mkdtemp()) dota_subdir = join(self.manager._dota_path(), "dota") if not isdir(dota_subdir): mkdir(dota_subdir) write_to_file(self.manager.dota_info_file(), self.dota_info_normal) # def tearDown(self): # self.manager._dota_path = self.real_method def test_is_modded_tester(self): write_to_file(self.manager.dota_info_file(), self.dota_info_normal) self.assertFalse(self.manager.is_modded(), "should NOT be modded") write_to_file(self.manager.dota_info_file(), self.dota_info_modded) self.assertTrue(self.manager.is_modded(), "should be modded") def test_mod_game_info(self): self.assertFalse(self.manager.is_modded(), "game info schould NOT be modded at the beginning") self.manager.mod_game_info() self.assertTrue(self.manager.is_modded(), "game info schould be modded now") def test_unmod_game_info(self): self.manager.mod_game_info() self.assertTrue(self.manager.is_modded(), "game info schould be modded at the beginning") self.manager.unmod_game_info() self.assertFalse(self.manager.is_modded(), "game info schould NOT be modded anymore")
class SingleApplication(QApplication): def __init__(self, *args): QApplication.__init__(self, *args) self._memory = QSharedMemory(self) self._memory.setKey("d2mp") if self._memory.attach(): self._running = True else: self._running = False if not self._memory.create(1): raise RuntimeError(self._memory.errorString().toLocal8Bit().data()) def is_running(self): return self._running def exec_(self): self._create_tray_icon() self._create_mod_manager() self._start_file_watcher() self._create_socket() Settings() return super(SingleApplication, self).exec_() def _create_mod_manager(self): self.manager = ModManager() self.manager.mod_game_info() self.manager.signals.message.connect(self.show_message_from_mod_manager) self.manager.signals.error.connect(self.show_error_from_mod_manager) def _create_socket(self): self.socket = ConnectionManager() self.manager.signals.contact_server.connect(self.socket.send) self.socket.message.connect(self.show_message_from_socket) self.socket.error.connect(self.show_error_from_socket) @property def _watcher_file_name(self): return "d2mp.pid" def _start_file_watcher(self): self.watcher = QFileSystemWatcher() self.watcher_file_path = join(abspath("."), self._watcher_file_name) log.DEBUG("creating watcher file: %s" %(self.watcher_file_path)) write_to_file(self.watcher_file_path, "Delete this file to shutdown D2MP\n") self.watcher.addPath(abspath(".")) self.watcher.directoryChanged.connect(self._watcher_changed_callback) def _watcher_changed_callback(self, val): if self._watcher_file_name not in os.listdir(val): secs = 3 self.show_message("Shutdown", "Watcher file was deleted. D2MP will shotdown in %d seconds." %(secs)) sleep(secs) self.exit() def _create_tray_icon(self): self.tray = QSystemTrayIcon(self) self.tray.setToolTip("D2Moddin Manager") self.tray.setIcon(QIcon(SETTINGS['icon'])) traymenu = QMenu() traymenu.addAction("Restart", self.restart) traymenu.addAction("Uninstall", self.uninstall) traymenu.addAction("Preferences", UIManager().open_preferences) traymenu.addAction("Show mod list", self.show_mod_list) traymenu.addSeparator() traymenu.addAction("Exit", self.exit) self.tray.setContextMenu(traymenu) self.tray.show() def restart(self): python = sys.executable args = set(sys.argv) args.add("restart") os.execl(python, python, *list(sys.argv)) self.exit() def uninstall(self): ModManager().delete_mods() # ModManager().uninstall_d2mp() self.exit() def exit(self): # do some cleanup return super(SingleApplication, self).exit() def show_mod_list(self): self.show_message("Mod List", ModManager().mod_names_as_string()) def show_message_from_socket(self, message): self.show_message("Server message", message) def show_error_from_socket(self, message): self.show_message("Server error", message, QSystemTrayIcon.Critical) def show_message_from_mod_manager(self, message): self.show_message("ModManager message", message) def show_error_from_mod_manager(self, message): self.show_message("ModManager error", message, QSystemTrayIcon.Critical) def show_message(self, title, message, icon = QSystemTrayIcon.Information): self.tray.showMessage(title, message, icon)