Exemple #1
0
    def __init__(self, parent, modDir, modinfo, *args, **kwargs):
        BaseClass.__init__(self, *args, **kwargs)

        self.setupUi(self)
        self.parent = parent
        self.client = self.parent.client
        self.modinfo = modinfo
        self.modDir = modDir
        
        self.setStyleSheet(self.parent.client.styleSheet())
        
        self.setWindowTitle("Uploading Mod")

        self.Name.setText(modinfo.name)
        self.Version.setText(str(modinfo.version))
        if modinfo.ui_only: self.isUILabel.setText("is UI Only")
        else: self.isUILabel.setText("not UI Only")
        self.UID.setText(modinfo.uid)
        self.Description.setPlainText(modinfo.description)
        if modinfo.icon != "":
            self.IconURI.setText(modvault.iconPathToFull(modinfo.icon))
            self.updateThumbnail()
        else:
            self.Thumbnail.setPixmap(util.pixmap("games/unknown_map.png"))
        self.UploadButton.pressed.connect(self.upload)
Exemple #2
0
    def upload(self):
        n = self.Name.text()
        if any([(i in n) for i in '"<*>|?/\\:']):
            QtGui.QMessageBox.information(self.client,"Invalid Name",
                        "The mod name contains invalid characters: /\\<>|?:\"")
            return

        iconpath = modvault.iconPathToFull(self.modinfo.icon)
        infolder = False
        if iconpath != "" and os.path.commonprefix([os.path.normcase(self.modDir),os.path.normcase(iconpath)]) == os.path.normcase(self.modDir): #the icon is in the game folder
            localpath = modvault.fullPathToIcon(iconpath)
            infolder = True
        if iconpath != "" and not infolder:
            QtGui.QMessageBox.information(self.client,"Invalid Icon File",
                        "The file %s is not located inside the modfolder. Copy the icon file to your modfolder and change the mod_info.lua accordingly" % iconpath)
            return

        try:
            temp = tempfile.NamedTemporaryFile(mode='w+b', suffix=".zip", delete=False)
            zipped = zipfile.ZipFile(temp, "w", zipfile.ZIP_DEFLATED)
            zipdir(self.modDir, zipped, os.path.basename(self.modDir))
            zipped.close()
            temp.flush()
        except:
            QtGui.QMessageBox.critical(self.client, "Mod uploading error", "Something went wrong zipping the mod files.")
            return
        qfile =QtCore.QFile(temp.name)

        #The server should check again if there is already a mod with this name or UID.
        self.client.writeToServer("UPLOAD_MOD", "%s.v%04d.zip" % (self.modinfo.name, self.modinfo.version), self.modinfo.to_dict(), qfile)
Exemple #3
0
    def __init__(self, parent, modDir, modinfo, *args, **kwargs):
        BaseClass.__init__(self, *args, **kwargs)

        self.setupUi(self)
        self.parent = parent
        self.client = self.parent.client
        self.modinfo = modinfo
        self.modDir = modDir
        #self.oldname = self.modinfo["name"]

        self.setStyleSheet(self.parent.client.styleSheet())

        self.setWindowTitle("Uploading Mod")

        self.Name.setText(modinfo.name)
        self.Version.setText(str(modinfo.version))
        if modinfo.ui_only: self.isUILabel.setText("is UI Only")
        else: self.isUILabel.setText("not UI Only")
        #self.UIOnly.setChecked(modinfo["ui_only"])
        self.UID.setText(modinfo.uid)
        self.Description.setPlainText(modinfo.description)
        if modinfo.icon != "":
            self.IconURI.setText(modvault.iconPathToFull(modinfo.icon))
            self.updateThumbnail()
        else:
            self.Thumbnail.setPixmap(util.pixmap("games/unknown_map.png"))
        #self.IconURI.returnPressed.connect(self.updateThumbnail)
        self.UploadButton.pressed.connect(self.upload)
Exemple #4
0
 def updateThumbnail(self):
     iconfilename = modvault.iconPathToFull(self.modinfo.icon)
     if iconfilename == "":
         return False
     if os.path.splitext(iconfilename)[1].lower() == ".dds":
         old = iconfilename
         iconfilename = os.path.join(
             self.modDir,
             os.path.splitext(os.path.basename(iconfilename))[0] + ".png")
         succes = modvault.generateThumbnail(old, iconfilename)
         if not succes:
             logger.info("Could not write the png file for %s" % old)
             QtGui.QMessageBox.information(
                 self.client, "Invalid Icon File",
                 "Because FAF can't read DDS files, it tried to convert it to a png. This failed. Try something else"
             )
             return False
     try:
         self.Thumbnail.setPixmap(util.pixmap(iconfilename, False))
     except:
         QtGui.QMessageBox.information(
             self.client, "Invalid Icon File",
             "This was not a valid icon file. Please pick a png or jpeg")
         return False
     self.modinfo.thumbnail = modvault.fullPathToIcon(iconfilename)
     self.IconURI.setText(iconfilename)
     return True
Exemple #5
0
    def upload(self):
        n = self.Name.text()
        if any([(i in n) for i in '"<*>|?/\\:']):
            QtGui.QMessageBox.information(
                self.client, "Invalid Name",
                "The mod name contains invalid characters: /\\<>|?:\"")
            return

        iconpath = modvault.iconPathToFull(self.modinfo.icon)
        infolder = False
        if iconpath != "" and os.path.commonprefix([
                os.path.normcase(self.modDir),
                os.path.normcase(iconpath)
        ]) == os.path.normcase(self.modDir):  #the icon is in the game folder
            localpath = modvault.fullPathToIcon(iconpath)
            infolder = True
        if iconpath != "" and not infolder:
            QtGui.QMessageBox.information(
                self.client, "Invalid Icon File",
                "The file %s is not located inside the modfolder. Copy the icon file to your modfolder and change the mod_info.lua accordingly"
                % iconpath)
            return

        try:
            temp = tempfile.NamedTemporaryFile(mode='w+b',
                                               suffix=".zip",
                                               delete=False)
            zipped = zipfile.ZipFile(temp, "w", zipfile.ZIP_DEFLATED)
            zipdir(self.modDir, zipped, os.path.basename(self.modDir))
            zipped.close()
            temp.flush()
        except:
            QtGui.QMessageBox.critical(
                self.client, "Mod uploading error",
                "Something went wrong zipping the mod files.")
            return
        qfile = QtCore.QFile(temp.name)

        #The server should check again if there is already a mod with this name or UID.
        self.client.writeToServer(
            "UPLOAD_MOD",
            "%s.v%04d.zip" % (self.modinfo.name, self.modinfo.version),
            self.modinfo.to_dict(), qfile)
Exemple #6
0
 def updateThumbnail(self):
     iconfilename = modvault.iconPathToFull(self.modinfo.icon)
     if iconfilename == "":
         return False
     if os.path.splitext(iconfilename)[1].lower() == ".dds":
         old = iconfilename
         iconfilename = os.path.join(self.modDir, os.path.splitext(os.path.basename(iconfilename))[0] + ".png")
         succes = modvault.generateThumbnail(old,iconfilename)
         if not succes:
             QtGui.QMessageBox.information(self.client,"Invalid Icon File",
                     "Because FAF can't read DDS files, it tried to convert it to a png. This failed. Try something else")
             return False
     try:
         self.Thumbnail.setPixmap(util.pixmap(iconfilename,False))
     except:
         QtGui.QMessageBox.information(self.client,"Invalid Icon File",
                     "This was not a valid icon file. Please pick a png or jpeg")
         return False
     self.modinfo.thumbnail = modvault.fullPathToIcon(iconfilename)
     self.IconURI.setText(iconfilename)
     return True
Exemple #7
0
    def upload(self):
        n = self.Name.text()
        if any([(i in n) for i in '"<*>|?/\\:']):
            QtGui.QMessageBox.information(
                self.client, "Invalid Name",
                "The mod name contains invalid characters: /\\<>|?:\"")
            return

#        if not self.updateThumbnail():
#            QtGui.QMessageBox.information(self.client,"No thumbnail",
#                        "There is no thumbnail attached")
#            return

#self.modinfo["name"] = n
#self.modinfo["uid"] = self.UID.text()
#self.modinfo["description"] = self.Description.toPlainText()
#self.modinfo["version"] = int(self.Version.text())

        iconpath = modvault.iconPathToFull(self.modinfo.icon)
        #self.modinfo["name"] = n
        #self.modinfo["uid"] = self.UID.text()
        #self.modinfo["description"] = self.Description.toPlainText()
        #self.modinfo["version"] = int(self.Version.text())

        iconpath = modvault.iconPathToFull(self.modinfo.icon)
        infolder = False
        if iconpath != "" and os.path.commonprefix([
                os.path.normcase(self.modDir),
                os.path.normcase(iconpath)
        ]) == os.path.normcase(self.modDir):  #the icon is in the game folder
            localpath = modvault.fullPathToIcon(iconpath)
            infolder = True
        '''
        if self.oldname.lower() != self.modinfo["name"].lower(): # we need to change the name of the folder correspondingly
            try:
                os.rename(os.path.join(modvault.MODFOLDER, self.oldname),
                          os.path.join(modvault.MODFOLDER, self.modinfo["name"]))
                self.oldname = self.modinfo["name"]
            except:
                QtGui.QMessageBox.information(self.client,"Changing folder name",
                        "Because you changed the mod name, the folder name \
                         has to change as well. This failed.")
                return
            if infolder == True:
                iconpath = "/mods/" + self.modinfo["name"] +"/" + "/".join(localpath.split('/')[3:])
            self.modDir = os.path.join(modvault.MODFOLDER, self.modinfo["name"])
        '''
        if iconpath != "" and not infolder:
            QtGui.QMessageBox.information(
                self.client, "Invalid Icon File",
                "The file %s is not located inside the modfolder. Copy the icon file to your modfolder and change the mod_info.lua accordingly"
                % iconpath)
            return
            '''
            newpath = os.path.join(self.modDir, os.path.split(iconpath)[1])
            f = open(iconpath, 'r')
            data = r.read()
            f.close()
            f = open(newpath, 'w')
            f.write(data)
            f.close()
            iconpath = modvault.fullPathToIcon(newpath)
        elif iconpath != "":
            iconpath = modvault.fullPathToIcon(iconpath)
        '''
        #self.modinfo["icon"] = iconpath

        #if not modvault.updateModInfo(self.modinfo["name"], self.modinfo):
        #    QtGui.QMessageBox.information(self.client,"Error updating Mod Info",
        #                "FAF could not read or write to the mod_info.lua file.")
        #    return

        try:
            temp = tempfile.NamedTemporaryFile(mode='w+b',
                                               suffix=".zip",
                                               delete=False)
            zipped = zipfile.ZipFile(temp, "w", zipfile.ZIP_DEFLATED)
            zipdir(self.modDir, zipped, os.path.basename(self.modDir))
            zipped.close()
            temp.flush()
        except:
            QtGui.QMessageBox.critical(
                self.client, "Mod uploading error",
                "Something went wrong zipping the mod files.")
            return
        qfile = QtCore.QFile(temp.name)

        self.modinfo.big = (self.SizeType.currentIndex() == 1)
        self.modinfo.small = (self.SizeType.currentIndex() == 2)

        #The server should check again if there is already a mod with this name or UID.
        self.client.writeToServer(
            "UPLOAD_MOD",
            "%s.v%04d.zip" % (self.modinfo.name, self.modinfo.version),
            self.modinfo.to_dict(), qfile)
Exemple #8
0
    def upload(self):
        n = self.Name.text()
        if any([(i in n) for i in '"<*>|?/\\:']):
            QtGui.QMessageBox.information(self.client,"Invalid Name",
                        "The mod name contains invalid characters: /\\<>|?:\"")
            return


#        if not self.updateThumbnail():
#            QtGui.QMessageBox.information(self.client,"No thumbnail",
#                        "There is no thumbnail attached")
#            return

        #self.modinfo["name"] = n
        #self.modinfo["uid"] = self.UID.text()
        #self.modinfo["description"] = self.Description.toPlainText()
        #self.modinfo["version"] = int(self.Version.text())

        iconpath = modvault.iconPathToFull(self.modinfo.icon)
        #self.modinfo["name"] = n
        #self.modinfo["uid"] = self.UID.text()
        #self.modinfo["description"] = self.Description.toPlainText()
        #self.modinfo["version"] = int(self.Version.text())

        iconpath = modvault.iconPathToFull(self.modinfo.icon)
        infolder = False
        if iconpath != "" and os.path.commonprefix([os.path.normcase(self.modDir),os.path.normcase(iconpath)]) == os.path.normcase(self.modDir): #the icon is in the game folder
            localpath = modvault.fullPathToIcon(iconpath)
            infolder = True
        '''
        if self.oldname.lower() != self.modinfo["name"].lower(): # we need to change the name of the folder correspondingly
            try:
                os.rename(os.path.join(modvault.MODFOLDER, self.oldname),
                          os.path.join(modvault.MODFOLDER, self.modinfo["name"]))
                self.oldname = self.modinfo["name"]
            except:
                QtGui.QMessageBox.information(self.client,"Changing folder name",
                        "Because you changed the mod name, the folder name \
                         has to change as well. This failed.")
                return
            if infolder == True:
                iconpath = "/mods/" + self.modinfo["name"] +"/" + "/".join(localpath.split('/')[3:])
            self.modDir = os.path.join(modvault.MODFOLDER, self.modinfo["name"])
        '''
        if iconpath != "" and not infolder:
            QtGui.QMessageBox.information(self.client,"Invalid Icon File",
                        "The file %s is not located inside the modfolder. Copy the icon file to your modfolder and change the mod_info.lua accordingly" % iconpath)
            return
            '''
            newpath = os.path.join(self.modDir, os.path.split(iconpath)[1])
            f = open(iconpath, 'r')
            data = r.read()
            f.close()
            f = open(newpath, 'w')
            f.write(data)
            f.close()
            iconpath = modvault.fullPathToIcon(newpath)
        elif iconpath != "":
            iconpath = modvault.fullPathToIcon(iconpath)
        '''
        #self.modinfo["icon"] = iconpath
            
        #if not modvault.updateModInfo(self.modinfo["name"], self.modinfo):
        #    QtGui.QMessageBox.information(self.client,"Error updating Mod Info",
        #                "FAF could not read or write to the mod_info.lua file.")
        #    return
        
        try:
            temp = tempfile.NamedTemporaryFile(mode='w+b', suffix=".zip", delete=False)
            zipped = zipfile.ZipFile(temp, "w", zipfile.ZIP_DEFLATED)
            zipdir(self.modDir, zipped, os.path.basename(self.modDir))
            zipped.close()
            temp.flush()
        except:
            QtGui.QMessageBox.critical(self.client, "Mod uploading error", "Something went wrong zipping the mod files.")
            return
        qfile =QtCore.QFile(temp.name)

        self.modinfo.big = (self.SizeType.currentIndex() == 1)
        self.modinfo.small = (self.SizeType.currentIndex() == 2)
        
        #The server should check again if there is already a mod with this name or UID.
        self.client.writeToServer("UPLOAD_MOD", "%s.v%04d.zip" % (self.modinfo.name, self.modinfo.version), self.modinfo.to_dict(), qfile)