예제 #1
0
def copyOther(ignoredAttributes):
    print("\nCopying Other folder for " + systemName + ".")
    newOtherFiles = []
    failedOtherFiles = []
    numFiles = 0
    for root, dirs, files in walk(path.join(otherFolder, systemName)):
        for file in files:
            numFiles += 1
    step = max(numFiles // 20, 1)
    currFileNum = 0
    sourceSystemOtherDir = path.join(otherFolder, systemName)
    for root, dirs, files in walk(sourceSystemOtherDir):
        for fileName in files:
            currRoot = root.split(sourceSystemOtherDir)[1][1:]
            oldFileDirPathArray = getPathArray(root)
            if arrayOverlap(ignoredAttributes, oldFileDirPathArray):
                continue
            newFileDir = path.join(outputFolder, systemName, currRoot)
            newFile = path.join(newFileDir, fileName)
            if not path.isfile(newFile):
                createDir(newFileDir)
                oldFile = path.join(root, fileName)
                try:
                    shutil.copy(oldFile, newFile)
                    newOtherFiles.append(newFile)
                except:
                    print("The following file failed to copy: " + oldFile)
                    failedOtherFiles.append(oldFile)
                    if listdir(newFileDir) == 0:
                        rmdir(newFileDir)
            currFileNum += 1
            if currFileNum % step == 0:
                print(
                    str(round(currFileNum * 100.0 / numFiles, 1)) +
                    "% - Confirmed " + str(currFileNum) + " of " +
                    str(numFiles) + ".")
    print("\nCopied " + str(len(newOtherFiles)) + " new files.")
    print("Finished copying Other folder.")
    if logFolder != "":
        print("Generating New Other log.")
        createNewFromOtherLog(newOtherFiles, failedOtherFiles)
        print("Done.")
예제 #2
0
def updateOther():
    updateFolderName = path.basename(updateFromDeviceFolder)
    print("\nUpdating " + updateFolderName + " folder from " + deviceName +
          ".")
    newFilesInOther = []
    failedOtherFiles = []
    for root, dirs, files in walk(outputFolder):
        dirs[:] = [d for d in dirs if d not in skippedFoldersOnDevice]
        currRoot = root.split(outputFolder)[1][1:]
        try:
            currSystem = getPathArray(currRoot)[0]
        except:
            currSystem = ""
        for file in files:
            fileInOutput = path.join(root, file)
            fileInRomset = path.join(romsetFolder, currSystem, file)
            fileInOther = path.join(otherFolder, currRoot, file)
            updateFolder = path.join(updateFromDeviceFolder, currRoot)
            fileInUpdate = path.join(updateFolder, file)
            if not (path.isfile(fileInRomset) or path.isfile(fileInOther)
                    or path.isfile(fileInUpdate)):
                createDir(updateFolder)
                try:
                    shutil.copy(fileInOutput, fileInUpdate)
                    print("From " + deviceName + " to " + updateFolderName +
                          ": " + fileInUpdate)
                    newFilesInOther.append(fileInUpdate)
                except:
                    print("The following file failed to copy: " + fileInOutput)
                    failedOtherFiles.append(fileInOutput)
    print("\nSuccessfully updated " + updateFolderName + " folder with " +
          str(len(newFilesInOther)) + " new files.")
    print("\nRemoving empty folders from " + updateFolderName + "...")
    removeEmptyFolders(updateFromDeviceFolder)
    print("Done.")
    if logFolder != "":
        print("Generating New Files In " + updateFolderName + " log.")
        createNewInOtherLog(newFilesInOther, failedOtherFiles)
        print("Done.")
예제 #3
0
def main():
    global systemName
    global deviceName
    global deviceProfile
    global outputFolder
    global systemFolder
    global databaseFile
    global isNoIntro
    global skippedFoldersOnDevice

    clearScreen()
    print("\n########################")
    print("# Rom Organizer Deluxe #")
    print("########################\n")

    deviceProfiles = listdir(profilesFolder)
    if len(deviceProfiles) > 0:
        dp = makeChoice(
            "\nSelect a device profile (which device are you copying to?)",
            [path.splitext(prof)[0]
             for prof in deviceProfiles] + ["Create new profile"])
        if dp == len(deviceProfiles) + 1:
            createDeviceProfile()
        else:
            dn = deviceProfiles[dp - 1]
            deviceProfile = path.join(profilesFolder, dn)
            deviceName = path.splitext(dn)[0]
    else:
        print(
            "\nNo device profiles found. Please follow these steps to create a new profile."
        )
        createDeviceProfile()
    currProfileSystemDirs = [
        d for d in systemDirs if getRomsetCategory(d) != "None"
    ]
    if len(currProfileSystemDirs) == 0:
        if len(systemDirs) > 0:
            print("The current profile does not allow any romsets.")
        systemChoices = []
    else:
        systemChoices = makeChoice(
            "Select romset(s). You can select multiple choices by separating them with spaces:",
            currProfileSystemDirs + ["All", "None"],
            allowMultiple=True)
        if len(currProfileSystemDirs) + 2 in systemChoices:
            systemChoices = []
        elif len(currProfileSystemDirs) + 1 in systemChoices:
            systemChoices = list(range(1, len(currProfileSystemDirs) + 1))
    if otherFolder != "":
        otherFolderName = path.basename(otherFolder)
        currProfileOtherDirs = [
            d for d in otherDirs if getOtherCategory(d) == "True"
        ]
        if len(currProfileSystemDirs) == 0:
            if len(otherDirs) > 0:
                print("The current profile does not allow any " +
                      otherFolderName + " folders.")
            otherChoices = []
        else:
            otherChoices = makeChoice(
                "Select system(s) from " + otherFolderName +
                " folder. You can select multiple choices by separating them with spaces:",
                currProfileOtherDirs + ["All", "None"],
                allowMultiple=True)
            if len(currProfileOtherDirs) + 2 in otherChoices:
                otherChoices = []
            elif len(currProfileOtherDirs) + 1 in otherChoices:
                otherChoices = list(range(1, len(currProfileOtherDirs) + 1))
        if updateFromDeviceFolder != "":
            updateOtherChoice = makeChoice(
                "Update \"" + path.basename(updateFromDeviceFolder) +
                "\" folder by adding any files that are currently exclusive to "
                + deviceName + "?", ["Yes", "No"])
        else:
            updateOtherChoice = 2
    ignoredAttributes = getIgnoredAttributes()
    primaryRegions = getPrimaryRegions()
    skippedFoldersOnDevice = getSkippedOtherFolders()
    if len(systemChoices) > 0:
        ai = makeChoice("How should unfound database entries be handled?", [
            "Pause when a database entry is not found so I can correct it",
            "Skip all interruptions"
        ])
        allowInterruptions = (ai == 1)
    else:
        allowInterruptions = False
    print("\nPlease select the ROM directory of your " + deviceName +
          " (example: F:/Roms).")
    root = Tk()
    root.withdraw()
    outputFolder = ""
    while outputFolder == "":
        outputFolder = filedialog.askdirectory()
        if outputFolder != "":
            isCorrect = makeChoice(
                "Are you sure this is the correct folder?\n" + outputFolder,
                ["Yes", "No"])
            if isCorrect == 2:
                outputFolder = ""
    clearScreen()
    if logFolder != "":
        createDir(logFolder)
    for sc in systemChoices:
        systemName = currProfileSystemDirs[sc - 1]
        romsetCategory = getRomsetCategory(systemName)
        if romsetCategory in ["Full", "1G1R", "1G1R Primary"]:
            systemFolder = path.join(romsetFolder, systemName)
            systemNameLower = systemName.lower()
            numParenInSN = systemNameLower.count("(")
            isNoIntro = True
            databaseFile = ""
            for f in listdir(redumpDir):
                if f.split(" - Datfile")[0].strip().lower() == systemNameLower:
                    databaseFile = path.join(redumpDir, f)
                    isNoIntro = False
                    break
            if databaseFile == "":
                for f in listdir(noIntroDir):
                    if f.split(" (XMDB)")[0].replace(
                            " (Encrypted)",
                            "").replace(" (Decrypted)", "").replace(
                                " (BigEndian)",
                                "").replace(" (LittleEndian)", "").replace(
                                    " (WAD)",
                                    "").strip().lower() == systemNameLower:
                        databaseFile = path.join(noIntroDir, f)
                        break
                if databaseFile == "":
                    print("Database file for current system not found.")
                    print("Skipping current system.")
                    continue
            fixNamesAndGenerateMergeDict(allowInterruptions)
            copyRomset(romsetCategory, ignoredAttributes, primaryRegions)
    if otherFolder != "":
        for oc in otherChoices:
            otherChoice = currProfileOtherDirs[oc - 1]
            systemName = otherChoice
            otherCategory = getOtherCategory(systemName)
            if otherCategory == "True":
                copyOther(ignoredAttributes)
    if updateFromDeviceFolder != "":
        if updateOtherChoice == 1:
            updateOther()
    if logFolder != "":
        print(
            "\nReview the log files for more information on what files were excanged between the main drive and "
            + deviceName + ".")
    input("Press Enter to exit.")
예제 #4
0
def copyRomset(romsetCategory, ignoredAttributes, primaryRegions):
    if romsetCategory not in ["Full", "1G1R", "1G1R Primary"]:
        return
    print("\nCopying romset for " + systemName + ".")
    newRomsetFiles = []
    failedRomsetFiles = []
    numGames = len(mergeDict.keys())
    step = max(numGames // 20, 1)
    currGameNum = 0
    numNewFilesInOutput = 0
    for gameNameAndRegionNum in mergeDict.keys():
        gameName, gameRegionNum = gameNameAndRegionNum
        currGame = mergeDict[gameNameAndRegionNum]
        bestRom = getBestRom(currGame)
        attributes = getAttributeSplit(bestRom)
        if gameName.startswith("[BIOS]"):
            gameRegion = "[BIOS]"
        elif "Test Program" in attributes:
            gameRegion = "[Test Program]"
        elif gameRegionNum == 0:
            gameRegion = "[USA]"
        elif gameRegionNum == 2:
            gameRegion = "[Europe]"
        elif gameRegionNum in [1, 3, 4]:
            gameRegion = "[Other (English)]"
        elif gameRegionNum == 5:
            gameRegion = "[Japan]"
        else:
            gameRegion = "[Other (non-English)]"
        if gameRegion in primaryRegions:
            gameRegion = ""
        unlicensedStr = "[Unlicensed]" if "Unl" in attributes else ""
        unreleasedStr = "[Unreleased]" if "Proto" in attributes else ""
        compilationStr = "[Compilations]" if (
            systemName == "Nintendo - Game Boy Advance"
            and any([gameName.startswith(comp)
                     for comp in compilationArray])) else ""
        classicNESStr = "[NES & Famicom]" if (
            systemName == "Nintendo - Game Boy Advance"
            and any([gameName.startswith(nes)
                     for nes in classicNESArray])) else ""
        gbaVideoStr = "[GBA Video]" if gameName.startswith(
            "Game Boy Advance Video") else ""
        demoStr = "[Demos]" if "Sample" in attributes or "Demo" in attributes else ""
        redumpCategory = categoryDict[gameName]
        if redumpCategory == "Games":
            redumpCategory = ""
        else:
            if redumpCategory in [
                    unlicensedStr, unreleasedStr, compilationStr,
                    classicNESStr, gbaVideoStr, demoStr
            ]:
                redumpCategory = ""
            else:
                redumpCategory = "[" + redumpCategory + "]"
        if romsetCategory == "Full":
            for rom in currGame:
                oldFile = path.join(systemFolder, rom)
                newDir = path.join(outputFolder, systemName, gameRegion,
                                   compilationStr, classicNESStr, gbaVideoStr,
                                   unlicensedStr, demoStr, redumpCategory,
                                   unreleasedStr, gameName)
                newDirPathArray = getPathArray(newDir)
                if arrayOverlap(ignoredAttributes, newDirPathArray):
                    continue
                newFile = path.join(newDir, rom)
                if not path.isfile(newFile):
                    createDir(newDir)
                    try:
                        shutil.copy(oldFile, newFile)
                        newRomsetFiles.append(rom)
                    except:
                        print("The following rom failed to copy: " + rom)
                        failedRomsetFiles.append(rom)
        elif romsetCategory == "1G1R" or gameRegion == "":
            oldFile = path.join(systemFolder, bestRom)
            newDir = path.join(outputFolder, systemName, gameRegion,
                               compilationStr, classicNESStr, gbaVideoStr,
                               unlicensedStr, unreleasedStr, gameName)
            newDirPathArray = getPathArray(newDir)
            if arrayOverlap(ignoredAttributes, newDirPathArray):
                continue
            newFile = path.join(newDir, bestRom)
            if not path.isfile(newFile):
                createDir(newDir)
                try:
                    shutil.copy(oldFile, newFile)
                    newRomsetFiles.append(bestRom)
                except:
                    print("The following rom failed to copy: " + bestRom)
                    failedRomsetFiles.append(bestRom)
                    if listdir(newDir) == 0:
                        rmdir(newDir)
        currGameNum += 1
        if currGameNum % step == 0:
            print(
                str(round(currGameNum * 100.0 / numGames, 1)) +
                "% - Confirmed " + str(currGameNum) + " of " + str(numGames) +
                " game folders.")
    print("\nCopied " + str(len(newRomsetFiles)) + " new files.")
    print("Finished copying romset.")
    if logFolder != "":
        print("Generating New Romset log.")
        createNewRomsetLog(newRomsetFiles, failedRomsetFiles)
        print("Done.")
예제 #5
0
    print("Settings file not found.")
    from settingsRebuilder import *
    rebuildSettingsFile()
    print(
        "Created new settings file as settings.py. Edit settings.py with your own directories."
    )
    input("Press Enter to exit.")
    sys.exit()

from gatelib import makeChoice, arrayOverlap, getPathArray, createDir, removeEmptyFolders, clearScreen

# User settings
if not path.isdir(profilesFolder):
    print("Profiles folder not found. Creating new folder as " +
          profilesFolder)
    createDir(profilesFolder)
if romsetFolder == "":
    systemDirs = []
elif not path.isdir(romsetFolder):
    print("WARNING: Could not find romset folder.")
    sleep(2)
    systemDirs = []
else:
    systemDirs = [
        d for d in listdir(romsetFolder)
        if path.isdir(path.join(romsetFolder, d))
    ]

if otherFolder == "":
    otherDirs = []
elif not path.isdir(otherFolder):