コード例 #1
0
ファイル: Profile.py プロジェクト: mdavis199/MergeWizard
    def copyFiles(self, src, dst, names=None, overwrite=True):
        """ Copy files from src directory to dst directory. Subfolders are ignored.
        If names is provided, copies only files matching those names. Symlinks are not
        copied """
        moDebug("Copying files from {} to {}. Names: {}".format(
            src, dst, names))
        srcDir = QDir(src, "", QDir.IgnoreCase, QDir.Files | QDir.NoSymLinks)
        dstDir = QDir(dst)

        if not srcDir.exists() or not dstDir.exists():
            moWarn("Failed to copy files with non-existant directories")
            return False

        success = True
        if names:
            srcDir.setNameFilters(names)
        fileNames = srcDir.entryList()
        for name in fileNames:
            if dstDir.exists(name):
                if not overwrite:
                    continue
                dstDir.remove(name)
            success = QFile.copy(srcDir.filePath(name), dstDir.filePath(name))
            if not success:
                moWarn('Failed to copy "{}" from "{}" to "{}"'.format(
                    name, src, dst))
        return success
コード例 #2
0
ファイル: PageZMerge.py プロジェクト: mdavis199/MergeWizard
 def messageBox(self, success: bool, msg: str):
     if not success:
         moWarn(msg)
         QMessageBox.critical(self, "MergeWizard", msg)
     else:
         moInfo(msg)
         QMessageBox.information(self, "MergeWizard", msg)
コード例 #3
0
ファイル: Profile.py プロジェクト: mdavis199/MergeWizard
 def restoreBackup(self, profileName: str):
     if not self.backupPathExists(profileName):
         moWarn(
             "Cannot restore files from backup. Backup does not exist for profile: {}"
             .format(profileName))
         return False
     return self.copyFiles(self.backupPath(profileName),
                           self.profilePath(profileName),
                           self.PROFILE_FILES, True)
コード例 #4
0
ファイル: Profile.py プロジェクト: mdavis199/MergeWizard
 def createBackupFolder(self, profileName: str):
     """ Create a backup folder in the profile. The profile must exist """
     profileDir = QDir(self.profilePath(profileName))
     if not profileDir.exists():
         raise ValueError(
             "Attempted to create backup folder in non-existant profile: {}"
             .format(profileName))
     if profileDir.exists(self.PROFILE_DIR):
         return True
     if not profileDir.mkdir(self.PROFILE_DIR):
         moWarn("Failed to create backup directory in profile: {}".format(
             profileName))
         return False
     return True
コード例 #5
0
 def selectPluginsByName(self, names: List[str]):
     if not names:
         return
     indexes = []
     startIndex = self.index(0, Column.PluginName)
     for n in names:
         matches = self.match(startIndex, Qt.DisplayRole, n, 1,
                              Qt.MatchExactly)
         if matches:
             indexes.append(matches[0])
         else:
             moWarn(self.tr("Failed to select plugin: {}").format(n))
     if indexes:
         self.selectPlugins(indexes, True)
コード例 #6
0
ファイル: DataLoader.py プロジェクト: mdavis199/MergeWizard
    def enableLoadingProfile(self,
                             enable: bool,
                             gameName="",
                             profileName="",
                             zeditFolder=""):
        if enable and (not gameName or not profileName or not zeditFolder):
            moWarn(
                "Skipping merges from zEdit profile: Check zEdit settings in MergeWizard's options."
            )
            self._enableLoadingProfile = False
            return

        self._enableLoadingProfile, self._gameName, self._profileName, self._zeditFolder = (
            enable,
            gameName,
            profileName,
            zeditFolder,
        )
コード例 #7
0
ファイル: DataLoader.py プロジェクト: mdavis199/MergeWizard
 def loadMergeFileForMod(self, mod: Mod):
     jsonFile = glob(
         escape(self.__organizer.getMod(mod.name).absolutePath()) +
         "/merge - */merge.json")
     if jsonFile:
         try:
             mergeFile = self.loadMergeFromFile(jsonFile[0])
             mergeFile.mergeFilePath = jsonFile[0]
             mergeFile.modIsActive = mod.active
             self.addMergeToPlugins(mergeFile)
             self._mergeFiles.append(mergeFile)
             self._mergeNames.add(mergeFile.modName)
         except OSError as ex:
             moWarn('Failed to open mergeFile file "{}": {}'.format(
                 jsonFile, ex.strerror))
         except ValueError as ex:
             moWarn('Failed to read mergeFile file "{}": {}'.format(
                 jsonFile, ex))
コード例 #8
0
ファイル: Profile.py プロジェクト: mdavis199/MergeWizard
    def createProfile(self, name):
        if self.profileExists(name):
            return True

        # TODO: need to fix up the name before creating the directory
        # Refer to https://github.com/ModOrganizer2/modorganizer-uibase/blob/13963ed37276ede1fb052b838f8b7828d0f8d2f5/src/utility.cpp#L612
        # Refer to https://github.com/ModOrganizer2/modorganizer/blob/9945beabf160c68852a8bdac07de255f04fd6886/src/profile.cpp#L80

        profilesDir = QDir(self.profilesFolder())
        if not profilesDir.mkdir(name):
            moWarn(
                self.tr("Failed to create profile folder: {}").format(
                    profilesDir.absoluteFilesPath(name)))
            return False
        self.profileCreated.emit(name)

        # copy all files (one level) from current profile to new profile
        return self.copyFiles(self.profilePath(), self.profilePath(name))
コード例 #9
0
 def selectMergeByName(self, name):
     """ This will select the merge in the view, causing the text box to also update, and
     will update the MergeModel's current merge.  This is one of this class's two ways
     of updating the MergeModel.
     The view emits a selectionChanged signal
     """
     flags = QItemSelectionModel.Clear | QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows
     model = self.ui.mergeView.model()
     idx = model.index(0, Column.Name)
     if name:
         idxForName = model.indexForMergeName(name)
         if not idxForName.isValid():
             moWarn("Failed to load merge: {}".format(name))
         else:
             idx = idxForName
     self.ui.mergeView.selectionModel().select(idx, flags)
     # update the current merge in the MergeModel
     self._setCurrentMerge(idx)
コード例 #10
0
ファイル: ZEditConfig.py プロジェクト: mdavis199/MergeWizard
    def loadProfile(shortGameName, profileName, zEditInstallFolder) -> Merges:
        zEditProfileDir = QDir(zEditInstallFolder + "/" +
                               ZEditConfig.RELATIVE_PROFILE_DIR)
        if not zEditProfileDir.exists():
            moWarn("Profiles path does not exist: {}".format(
                zEditProfileDir.absolutePath()))
            return

        profiles = ZEditConfig.parseProfileList(shortGameName)
        for name in profiles:
            if name == profileName:
                relName = name + "/merges.json"
                if not zEditProfileDir.exists(relName):
                    moWarn('Profile "{}" does not have a "merges.json" file.'.
                           format(name))
                    return
                try:
                    filePath = zEditProfileDir.absoluteFilePath(relName)
                    with open(filePath) as f:
                        m = Merges(json.load(f))
                        m.profileName = name
                        m.profilePath = filePath
                        return m
                except ValueError as ex:
                    moWarn(
                        'Failed to read zEdit profile. Invalid file: "{}": {}'.
                        format(filePath, str(ex)))
        moError('Profile "{}" was not found'.format(profileName))
        return Merges()
コード例 #11
0
    def run(self) -> None:
        merges: Set[MergeFile] = set()
        files = glob(self.modDir + "/*/*/merge.json")
        self._total = len(files)
        self._count = 0
        self._progress = 0

        for file in files:
            if self._stopped:
                return
            self.emitProgress()
            try:
                merge = self.loadMergeFromFile(file)
                merge.mergePath = file
                merge.modName = path.basename(path.dirname(path.dirname(file)))
                merges.add(merge)
            except OSError as ex:
                moWarn('Failed to open merge file "{}": {}'.format(
                    file, ex.strerror))
            except ValueError as ex:
                moWarn('Failed to read merge file "{}": {}'.format(file, ex))
        self.result.emit(list(merges))