def updateXiaoASOkeyword(jsonData, isHd): jsonfile = GetJsonFile(isHd) isOld = IsOldVersion(jsonData) if isOld: APPSTORE_KEYWORD = jsonData["APPSTORE_KEYWORD"] strStart = "XIAOMI_KEYWORD" else: APPSTORE_KEYWORD = jsonData["appstore"]["aso"] strStart = "aso_xiaomi" cn = APPSTORE_KEYWORD["cn"] en = APPSTORE_KEYWORD["en"] cn = cn.replace(",", " ") en = en.replace(",", " ") strEnd = "\"" strFile = common.GetFileString(jsonfile) strMid = "\"cn\": \"" strFile = replaceString2(strFile, strStart, strMid, strEnd, cn) strMid = "\"en\": \"" strFile = replaceString2(strFile, strStart, strMid, strEnd, en) common.saveString2File(strFile, jsonfile)
def autoPlusVersionOldVersion(isHd, jsonData): global versionCode strold = "\"APPVERSION_CODE_ANDROID\": \"" + versionCode + "\"" strold_version_android = "\"APPVERSION_ANDROID\": \"" + jsonData[ "APPVERSION_ANDROID"] + "\"" strold_version_ios = "\"APPVERSION_IOS\": \"" + jsonData[ "APPVERSION_IOS"] + "\"" int_v = int(versionCode) int_v = int_v + 1 versionCode = str(int_v) strnew = "\"APPVERSION_CODE_ANDROID\": \"" + versionCode + "\"" strnew_version_android = "\"APPVERSION_ANDROID\": \"" + versionCodeToVersion( ) + "\"" strnew_version_ios = "\"APPVERSION_IOS\": \"" + versionCodeToVersion( ) + "\"" # 替换json jsonfile = GetJsonFile(isHd) strOut = common.GetFileString(jsonfile) strOut = strOut.replace(strold, strnew) strOut = strOut.replace(strold_version_android, strnew_version_android) strOut = strOut.replace(strold_version_ios, strnew_version_ios) saveString2File(strOut, jsonfile)
def replaceStringOfFile2(filePath, strStart, strMid, strEnd, strReplace): strFile = common.GetFileString(filePath) # print strFile strOut = replaceString2(strFile, strStart, strMid, strEnd, strReplace) # print strOut # fp_name.seek(0) # fp_name.write(strOut) return strOut
def replaceScreenOrientation(filePath, isHd): strFile = common.GetFileString(filePath) str = "sensorPortrait" if isHd: str = "sensorLandscape" strFile = strFile.replace("_SCREENORIENTATION_", str) common.saveString2File(strFile, filePath)
def replaceStringOfFile(filePath, strStart, strEnd, strReplace): # f = open(filePath) # f = open(filePath,'r', encoding='UTF-8') strFile = common.GetFileString(filePath) # strFile.decode('utf-8') # print strFile strOut = replaceString(strFile, strStart, strEnd, strReplace) # print strOut # fp_name.seek(0) # fp_name.write(strOut) return strOut
def UpdateLanguageName(name_cn, name_en, ishd): dirconfig = common.GetConfigDataDir() csvfile = dirconfig + "/language/language.csv" strContent = common.GetFileString(csvfile) key_name = GetCSVName(strContent, ishd) head = "APP_NAME" if ishd: head = "APP_NAME_HD" str_new = head + "," + name_cn + "," + name_en # +"\n" replaceFile(csvfile, key_name, str_new)
def replaceXcodeUrlScheme(filePath, src, appid, idx): strFile = common.GetFileString(filePath) # <string>WEIXIN_APPID</string> if src == source.WEIXIN or src == source.WEIXINFRIEND: strOld = "<string>WEIXIN_APPID</string>" if src == source.WEIBO: strOld = "<string>WEIBO_APPID</string>" if src == source.QQ or src == source.QQZONE: if idx == 0: strOld = "<string>QQ_APPID0</string>" if idx == 1: strOld = "<string>QQ_APPID1</string>" strNew = "<string>" + config.XcodeUrlScheme(src, appid, idx) + "</string>" strOut = strFile.replace(strOld, strNew) saveString2File(strOut, filePath)
def UpdateXcodeProjectFile(fileProject, isHD): flag = os.path.exists(fileProject) if not flag: return package = AppInfo.GetPackage(source.IOS, isHD) # 读取xcode文件的包名 # PRODUCT_BUNDLE_IDENTIFIER = com.moonma.xiehanzi.pad; strFile = common.GetFileString(fileProject) strHead = "PRODUCT_BUNDLE_IDENTIFIER = " strEnd = ";" idx = strFile.find(strHead) if idx >= 0: idx += len(strHead) strOther = strFile[idx:] idx = strOther.find(strEnd) packageold = strOther[0:idx] print("packageold=" + packageold) strFile = strFile.replace(packageold, package) common.saveString2File(strFile, fileProject)
def ConfigXcodeProjectFile(self, fileProject): strFile = common.GetFileString(fileProject) # OTHER_LDFLAGS = ( # "$(inherited)", # "-weak_framework", # CoreMotion, # "-weak-lSystem", # ); # strold = "\"-weak-lSystem\"," strnew = "\"-weak-lSystem\",\n\"-ObjC\"," idx = strFile.find(strnew) if idx >= 0: return strFile = strFile.replace(strold, strnew) # DEVELOPMENT_TEAM strold = "DEVELOPMENT_TEAM = \"\"" strnew = "DEVELOPMENT_TEAM = \"Y9ZUK2WTEE\"" strFile = strFile.replace(strold, strnew) common.saveString2File(strFile, fileProject)
def replaceFile(filePath, strOld, strReplace): strFile = common.GetFileString(filePath) strOut = strFile.replace(strOld, strReplace) saveString2File(strOut, filePath)
def updateName(isHd, isAuto): appinfoOld = AppInfoOld(isHd) if appinfoOld.IsOldVersion(): # 转换 ConvertOld2New(isHd, appinfoOld) rootConfig = common.GetProjectConfigApp() strHD = "HD" project_ios = rootConfig + "/ios/project" project_android = rootConfig + "/android/project" if isHd: project_ios = rootConfig + "/ios/project_hd" project_android = rootConfig + "/android/project_hd" # android file_name_cn_android = project_android + "/res/values/strings.xml" file_name_en_android = project_android + "/res/values-en/strings.xml" file_AndroidManifest = project_android + "/xml/AndroidManifest.xml" file_AndroidManifest_GP = project_android + "/xml_gp/AndroidManifest.xml" file_google_service_android = project_android + "/config/google-services.json" # ios file_name_cn_ios = project_ios + "/appname/zh-Hans.lproj/InfoPlist.strings" file_name_en_ios = project_ios + "/appname/en.lproj/InfoPlist.strings" file_info_plist_ios = project_ios + "/Info.plist" # loadJson data = loadJson(isHd) isOld = IsOldVersion(data) global versionCode if not isOld: appname = data["appname"] if isOld: APP_NAME_CN_ANDROID = data["APP_NAME_CN_ANDROID"] APP_NAME_EN_ANDROID = data["APP_NAME_EN_ANDROID"] APP_NAME_CN_IOS = data["APP_NAME_CN_IOS"] APP_NAME_EN_IOS = data["APP_NAME_EN_IOS"] PACKAGE_ANDROID = data["PACKAGE_ANDROID"] PACKAGE_IOS = data["PACKAGE_IOS"] versionCode = data["APPVERSION_CODE_ANDROID"] APPVERSION_IOS = data["APPVERSION_IOS"] appid_huawei = GetConfigDataAppId(source.ANDROID, source.HUAWEI, isHd) else: APP_NAME_CN_ANDROID = appname[source.ANDROID]["cn"] APP_NAME_EN_ANDROID = appname[source.ANDROID]["en"] APP_NAME_CN_IOS = appname[source.IOS]["cn"] APP_NAME_EN_IOS = appname[source.IOS]["en"] PACKAGE_ANDROID = data["apppackage"][source.ANDROID]["default"] PACKAGE_IOS = data["apppackage"][source.IOS]["default"] versionCode = data["appversion"][source.ANDROID]["code"] APPVERSION_IOS = data["appversion"][source.IOS]["value"] #appid appid_ios = GetJsonAppId(data, source.APPSTORE) appid_taptap = GetJsonAppId(data, source.TAPTAP) appid_huawei = GetJsonAppId(data, source.HUAWEI) SetConfigDataAppId(source.IOS, source.APPSTORE, appid_ios, isHd) SetConfigDataAppId(source.ANDROID, source.TAPTAP, appid_taptap, isHd) SetConfigDataAppId(source.ANDROID, source.HUAWEI, appid_huawei, isHd) UpdateLanguageName(APP_NAME_CN_ANDROID, APP_NAME_EN_ANDROID, isHd) # if data.has_key("PACKAGE_HD_ANDROID"): # PACKAGE_HD_ANDROID = data["PACKAGE_HD_ANDROID"] if isAuto == True: autoPlusVersion(isHd, data) # 重新加载 data = loadJson(isHd) APPVERSION_ANDROID = versionCodeToVersion() APPVERSION_CODE_ANDROID = versionCode # appversion.json if isAuto == False: src = common.GetProjectConfigDefault() + "/appinfo/appversion.json" dst = common.GetProjectConfigApp() + "/appinfo/appversion.json" flag = os.path.exists(dst) # if not isHd: shutil.copyfile(src, dst) strfile = common.GetFileString(dst) key = "_VERSION_ANDROID_" if isHd: key = "_VERSION_HD_ANDROID_" version_web = mainAppVersionHuawei.ParseVersion(appid_huawei) strfile = strfile.replace(key, version_web) common.saveString2File(strfile, dst) filepath = common.GetProjectConfigAppType() + "/appversion.json" flag = os.path.exists(filepath) strFileJson = "{}" if flag: strFileJson = common.GetFileString(filepath) dataRoot = json.loads(strFileJson) dataRoot[common.getGameName()] = json.loads(strfile) common.SaveJson(filepath, dataRoot) print(APP_NAME_CN_ANDROID) print(APP_NAME_EN_ANDROID) print(APP_NAME_CN_IOS) print(APP_NAME_EN_IOS) print(PACKAGE_ANDROID) print("android version:" + APPVERSION_ANDROID) print("ios version:" + APPVERSION_IOS) # android # name strStart = "app_name\">" strEnd = "<" # cn strOut = replaceStringOfFile(file_name_cn_android, strStart, strEnd, APP_NAME_CN_ANDROID) saveString2File(strOut, file_name_cn_android) # en strOut = replaceStringOfFile(file_name_en_android, strStart, strEnd, APP_NAME_EN_ANDROID) saveString2File(strOut, file_name_en_android) updateAndroidManifest(file_AndroidManifest, PACKAGE_ANDROID, APPVERSION_ANDROID, APPVERSION_CODE_ANDROID, isHd) updateAndroidManifest(file_AndroidManifest_GP, PACKAGE_ANDROID, APPVERSION_ANDROID, APPVERSION_CODE_ANDROID, isHd) # admob replaceGoogleServiceFile(file_google_service_android, PACKAGE_ANDROID) # ios #appname replaceFile(file_info_plist_ios, "_APP_NAME_", APP_NAME_CN_IOS) file_name_cn_ios = project_ios + "/appname/zh-Hans.lproj/InfoPlist.strings" file_name_en_ios = project_ios + "/appname/en.lproj/InfoPlist.strings" # cn replaceFile(file_name_cn_ios, "_APP_NAME_", APP_NAME_CN_IOS) # en replaceFile(file_name_en_ios, "_APP_NAME_", APP_NAME_EN_IOS) # package replaceFile(file_info_plist_ios, "_APP_PACKAGE_", PACKAGE_IOS) # version replaceFile(file_info_plist_ios, "_APP_VERSION_", APPVERSION_IOS) #admob appid appid = adconfig.GetCommonAppId(source.ADMOB, source.IOS, isHd) replaceFile(file_info_plist_ios, "_APP_ID_ADMOB_", appid) # CFBundleURLSchemes src = source.WEIBO appid = config.GetShareAppId(src, source.IOS, isHd) replaceXcodeUrlScheme(file_info_plist_ios, src, appid, 0) src = source.WEIXIN appid = config.GetShareAppId(src, source.IOS, isHd) replaceXcodeUrlScheme(file_info_plist_ios, src, appid, 0) src = source.QQ appid = config.GetShareAppId(src, source.IOS, isHd) replaceXcodeUrlScheme(file_info_plist_ios, src, appid, 0) replaceXcodeUrlScheme(file_info_plist_ios, src, appid, 1) # xiaomi aso keyword updateXiaoASOkeyword(data, isHd) # win updateNameWin(isHd, isAuto)
def replaceFile(filePath, key, value): strFile = common.GetFileString(filePath) strFile = strFile.replace(key, value) common.saveString2File(strFile, filePath)
def replaceFileForKey(filePath, key, content): # f = open(filePath, 'rb') # f = open(filePath,'r', encoding='utf-8') strFile = common.GetFileString(filePath) strFile = strFile.replace(key, content) common.saveString2File(strFile, filePath)
def replacePackage(filePath, package): strFile = common.GetFileString(filePath) strFile = strFile.replace("_PACKAGE_", package) common.saveString2File(strFile, filePath)