MakeAppleCode.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. using System;
  2. using System.Web;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Data;
  6. using System.IO;
  7. using System.IO.Compression;
  8. using Customer.Source;
  9. using Common;
  10. using System.Text.RegularExpressions;
  11. using Infrastructure;
  12. using NuGet.Configuration;
  13. namespace Util.MakeApp
  14. {
  15. public class MakeAppleCode
  16. {
  17. #region 生成文件
  18. public static void MakerFile(string fileName, AppProject project, AppProjectVersion ver, List<AppModule> smodules, List<AppModuleIosCode> codes, List<AppProjectModule> modules, List<AppProjectParam> paramList, List<AppModuleFile> fileList, List<AppProjectPage> pages, List<AppProjectBottom> bottoms)
  19. {
  20. MakeAppCodePub.ProcessSet(ver.id);
  21. string AppPackage = project.packageName; //包名
  22. string AppIcon = project.appIcon; //应用桌面图标
  23. string AppName = project.appName; //应用名称
  24. string AppStartBg = project.appStartBg; //启动图
  25. string AppStartListPhoto = project.appStartListPhoto; //启动介绍轮播图
  26. string ApiHost = project.apiHost; //API主机头
  27. string ApiKind = project.appKind; //APP分类
  28. string AppStatic = ver.staticFile; //APP静态资源
  29. string InitPage = project.initPage; //APP首次加载界面
  30. //复制文件
  31. string sourceDir = Function.getPath("/AppTemplate/ios/omnipotent/"); //模版目录
  32. string destinationDir = Function.getPath("applecode/" + project.id + "/omnipotent/"); //生成目录
  33. CopyFolder(sourceDir, destinationDir);
  34. MakeAppCodePub.ProcessSet(ver.id);
  35. string sourceBaseDir = Function.getPath("/AppTemplate/ios/omega-ios-framework/OmegaBase/"); //模版目录
  36. string destinationBaseDir = Function.getPath("applecode/" + project.id + "/OmegaBase/"); //生成目录
  37. CopyFolder(sourceBaseDir, destinationBaseDir);
  38. //替换包名
  39. ReplaceAppPackage(destinationDir, AppPackage);
  40. ReplaceAppPackage(destinationBaseDir, AppPackage);
  41. MakeAppCodePub.ProcessSet(ver.id);
  42. //替换项目索引文件
  43. string projectIndexPath = destinationDir + "omnipotent.xcodeproj/";
  44. string projectIndexContent = Function.ReadInstanceByFull(projectIndexPath + "project.pbxproj");
  45. Match projectIndexContentRegex = Regex.Match(projectIndexContent, "attributesByRelativePath = {[\\s\\S]*?};");
  46. if (projectIndexContentRegex.Success)
  47. {
  48. string content = projectIndexContentRegex.Value;
  49. content = content.Replace("};", " /* 自定义模块 */\n };");
  50. projectIndexContent = projectIndexContent.Replace(projectIndexContentRegex.Value, content);
  51. }
  52. projectIndexContentRegex = Regex.Match(projectIndexContent, "membershipExceptions = ([\\s\\S]*?);");
  53. if (projectIndexContentRegex.Success)
  54. {
  55. string content = projectIndexContentRegex.Value;
  56. content = content.Replace(");", " /* 自定义模块名称 */\n );");
  57. projectIndexContent = projectIndexContent.Replace(projectIndexContentRegex.Value, content);
  58. }
  59. string customFrameworksIndex = "";
  60. string customFrameworksIndexName = "";
  61. // string startString = "/* Begin PBXFileReference section */";
  62. // string endString = "/* End PBXFileReference section */";
  63. // int startIndex = projectIndexContent.IndexOf(startString);
  64. // int length = projectIndexContent.IndexOf(endString) + endString.Length - startIndex;
  65. // string projectIndexList = projectIndexContent.Substring(startIndex, length);
  66. // List<string> fileIndexSources = projectIndexList.Replace(startString + "\n", "").Replace("\n" + endString, "").Replace("\t", "").Split('\n').ToList();
  67. List<string> fileIndexs = new List<string>();
  68. // string projectIndexReplace = startString + "\n";
  69. List<string> fileIndexFiles = new List<string>();
  70. //方法代码
  71. string webCodePath = destinationBaseDir + "OmegaBase/Conroller/";
  72. string webCodeContent = Function.ReadInstanceByFull(webCodePath + "LocalWebViewController.swift");
  73. webCodeContent += "\n\n//模块方法代码";
  74. webCodeContent = Function.ReplaceFirst(webCodeContent, "else if message.name == \"", "//模块调用代码 else if message.name == \"");
  75. string invokeCodeList = "";
  76. string webCodeList = "";
  77. //权限代码
  78. string rightCodePath = destinationDir + "omnipotent/";
  79. string rightCodeContent = Function.ReadInstanceByFull(rightCodePath + "Info.plist");
  80. string rightCodeList = "";
  81. string queriesSchemes = "";
  82. string urlTypes = "";
  83. //AppDelegate代码
  84. string appDelegateCodePath = destinationDir + "omnipotent/";
  85. string appDelegateCodeContent = Function.ReadInstanceByFull(appDelegateCodePath + "AppDelegate.swift");
  86. appDelegateCodeContent += "\n\n//AppDelegate委托代码";
  87. var importIndex = appDelegateCodeContent.LastIndexOf("import");
  88. var importTagIndex = appDelegateCodeContent.Substring(importIndex).IndexOf("\n") + importIndex;
  89. appDelegateCodeContent = appDelegateCodeContent.Substring(0, importTagIndex) + "\n//AppDelegate引用" + appDelegateCodeContent.Substring(importTagIndex + 1);
  90. appDelegateCodeContent = Function.ReplaceFirst(appDelegateCodeContent, "{", "//AppDelegate继承代码{");
  91. appDelegateCodeContent = appDelegateCodeContent.Replace("DispatchQueue.global().async {", "//AppDelegate启动代码\nDispatchQueue.global().async {\n //AppDelegate异步启动代码");
  92. string appDelegateCodeList = "";
  93. string appDelegateLaunchCodeList = "";
  94. string appDelegateLaunchAsyncCodeList = "";
  95. string appDelegateFunctionCodeList = "";
  96. string appDelegateAddList = "";
  97. MakeAppCodePub.ProcessSet(ver.id);
  98. //替换基础信息
  99. projectIndexContent = Regex.Replace(projectIndexContent, "INFOPLIST_KEY_CFBundleDisplayName = \".*?\";", "INFOPLIST_KEY_CFBundleDisplayName = \"" + AppName + "\";");
  100. projectIndexContent = Regex.Replace(projectIndexContent, "PRODUCT_BUNDLE_IDENTIFIER = .*?;", "PRODUCT_BUNDLE_IDENTIFIER = " + AppPackage + ";");
  101. string apiSet = Function.ReadInstanceByFull(destinationDir + "omnipotent/AppConfiguration.ini");
  102. string AppVersion = ver.versionName;
  103. projectIndexContent = Regex.Replace(projectIndexContent, "MARKETING_VERSION = .*?;", "MARKETING_VERSION = " + AppVersion +";");
  104. apiSet = Regex.Replace(apiSet, "kind\":\".*?\"", "kind\":\"" + ApiKind + "/" + AppVersion + "\"");
  105. apiSet = Regex.Replace(apiSet, "serverUrls\":\".*?\"", "serverUrls\":\"" + ApiHost + "\"");
  106. //读取项目所有关联模块
  107. List<int> moduleIds = modules.Select(m => m.moduleId).ToList();
  108. //读取模块配置参数
  109. Dictionary<string, string> paramDic = paramList.ToDictionary(m => m.paramName + "_" + m.moduleId, m => m.paramValue);
  110. foreach(AppProjectModule module in modules)
  111. {
  112. AppModule smodule = smodules.FirstOrDefault(m => m.id == module.moduleId);
  113. if(smodule != null)
  114. {
  115. List<AppModuleFile> files = fileList.Where(m => m.moduleId == module.moduleId && m.appType == "ios").ToList();
  116. foreach(AppModuleFile file in files)
  117. {
  118. string SourceFilePath = file.sourcePath;
  119. string ToPath = file.makePath;
  120. if(ToPath.EndsWith(".framework.zip"))
  121. fileIndexFiles.Add(ToPath.Substring(ToPath.LastIndexOf("/") + 1));
  122. if(ToPath.EndsWith(".framework.zip"))
  123. {
  124. // string fileName = ToPath.Substring(ToPath.LastIndexOf("/") + 1);
  125. // CopyFolder(Function.getPath("/temp/Template/IOS/module/" + fileName + "/"), destinationDir + "omnipotent/customFrameworks/" + fileName + "/");
  126. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + "/AppModule/ios" + SourceFilePath, destinationDir + "omnipotent/" + SourceFilePath);
  127. ZipFile.ExtractToDirectory(destinationDir + "omnipotent/" + SourceFilePath, destinationDir + ToPath.Replace(".zip", ""), true);
  128. File.Delete(destinationDir + "omnipotent/" + SourceFilePath);
  129. }
  130. if(module.moduleId == 1)
  131. {
  132. if(ToPath.EndsWith(".entitlements"))
  133. {
  134. // string fileName = ToPath.Substring(ToPath.LastIndexOf("/") + 1);
  135. // File.Copy(Function.getPath("/temp/Template/IOS/module/" + fileName), destinationDir + "omnipotent/" + fileName, true);
  136. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + "/AppModule/ios" + SourceFilePath, destinationDir + ToPath);
  137. }
  138. //解压阿里云推送配置文件
  139. if (paramDic.ContainsKey("AliyunPList"))
  140. {
  141. string pListPath = Function.getPath(paramDic["AliyunPList_" + module.moduleId]);
  142. string toPListPath = destinationDir + "omnipotent/";
  143. ZipFile.ExtractToDirectory(pListPath, toPListPath, true);
  144. }
  145. }
  146. }
  147. AppModuleIosCode code = codes.FirstOrDefault(m => m.moduleId == module.moduleId) ?? new AppModuleIosCode();
  148. string InvokeCode = Function.CheckNull(code.invokeCode);
  149. string WebCode = Function.CheckNull(code.webCode);
  150. string SystemFramework = Function.CheckNull(code.systemFramework);
  151. string SystemLib = Function.CheckNull(code.systemLib);
  152. string RightCode = Function.CheckNull(code.rightCode);
  153. string ProjectIndexCode = Function.CheckNull(code.projectIndexCode);
  154. string AppDelegate = Function.CheckNull(code.appDelegate);
  155. string AppDelegateLaunchCode = Function.CheckNull(code.appDelegateLaunchCode);
  156. string AppDelegateLaunchAsyncCode = Function.CheckNull(code.appDelegateLaunchAsyncCode);
  157. string AppDelegateCode = Function.CheckNull(code.appDelegateCode);
  158. string EntitlementsCode = Function.CheckNull(code.entitlementsCode);
  159. string AppDelegateAdd = Function.CheckNull(code.appDelegateAdd);
  160. // if(module.moduleId == 10)
  161. // {
  162. // RightCode = RightCode.Replace("<string>微信ID</string>", "<string>" + paramDic["WeChatAppId"] + "</string>");
  163. // RightCode = RightCode.Replace("微信ID", paramDic["WeChatAppId"]);
  164. // AppDelegateLaunchCode = AppDelegateLaunchCode.Replace("微信ID", paramDic["WeChatAppId"]);
  165. // }
  166. // if(module.moduleId == 11)
  167. // {
  168. // RightCode = RightCode.Replace("<string>支付宝ID</string>", "<string>ap" + paramDic["AlipayAppId"] + "</string>");
  169. // RightCode = RightCode.Replace("支付宝ID", "ap" + paramDic["AlipayAppId"]);
  170. // AppDelegateLaunchCode = AppDelegateLaunchCode.Replace("支付宝ID", paramDic["AlipayAppId"]);
  171. // }
  172. if(RightCode.Contains("${"))
  173. {
  174. MatchCollection matches = Regex.Matches(RightCode, "\\$\\{.*?\\}");
  175. foreach(Match match in matches)
  176. {
  177. string paramName = match.Value.Replace("${", "").Replace("}", "");
  178. if(paramDic.ContainsKey(paramName + "_" + module.moduleId)) RightCode = RightCode.Replace(match.Value, paramDic[paramName + "_" + module.moduleId]);
  179. }
  180. }
  181. if(AppDelegateLaunchCode.Contains("${"))
  182. {
  183. MatchCollection matches = Regex.Matches(AppDelegateLaunchCode, "\\$\\{.*?\\}");
  184. foreach(Match match in matches)
  185. {
  186. string paramName = match.Value.Replace("${", "").Replace("}", "");
  187. if(paramDic.ContainsKey(paramName + "_" + module.moduleId)) AppDelegateLaunchCode = AppDelegateLaunchCode.Replace(match.Value, paramDic[paramName + "_" + module.moduleId]);
  188. }
  189. }
  190. if(AppDelegateLaunchAsyncCode.Contains("${"))
  191. {
  192. MatchCollection matches = Regex.Matches(AppDelegateLaunchAsyncCode, "\\$\\{.*?\\}");
  193. foreach(Match match in matches)
  194. {
  195. string paramName = match.Value.Replace("${", "").Replace("}", "");
  196. if(paramDic.ContainsKey(paramName + "_" + module.moduleId)) AppDelegateLaunchAsyncCode = AppDelegateLaunchAsyncCode.Replace(match.Value, paramDic[paramName + "_" + module.moduleId]);
  197. }
  198. }
  199. //项目索引信息
  200. if(!string.IsNullOrEmpty(ProjectIndexCode))
  201. {
  202. fileIndexs.Add(ProjectIndexCode);
  203. }
  204. //模块方法代码
  205. if(!string.IsNullOrEmpty(WebCode))
  206. {
  207. webCodeList += "\n\n" + WebCode;
  208. }
  209. //模块调用代码
  210. if(!string.IsNullOrEmpty(InvokeCode))
  211. {
  212. invokeCodeList += InvokeCode;
  213. }
  214. //权限代码
  215. if(!string.IsNullOrEmpty(RightCode) && !rightCodeContent.Contains(RightCode))
  216. {
  217. if(RightCode.StartsWith("{") && RightCode.EndsWith("}"))
  218. {
  219. Dictionary<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(RightCode);
  220. foreach(string key in dic.Keys)
  221. {
  222. urlTypes += " <dict>\n";
  223. urlTypes += " <key>CFBundleTypeRole</key>\n";
  224. urlTypes += " <string>Editor</string>\n";
  225. urlTypes += " <key>CFBundleURLName</key>\n";
  226. urlTypes += " <string>" + key + "</string>\n";
  227. urlTypes += " <key>CFBundleURLSchemes</key>\n";
  228. urlTypes += " <array>\n";
  229. urlTypes += " <string>" + dic[key] + "</string>\n";
  230. urlTypes += " </array>\n";
  231. urlTypes += " </dict>\n";
  232. queriesSchemes += " <string>" + key + "</string>\n";
  233. }
  234. }
  235. else
  236. {
  237. rightCodeList += "\n" + RightCode;
  238. }
  239. }
  240. //AppDelegate代码
  241. if(!string.IsNullOrEmpty(AppDelegate))
  242. {
  243. string[] AppDelegates = AppDelegate.Split('\n');
  244. foreach(string sub in AppDelegates)
  245. {
  246. if(!appDelegateCodeList.Contains(sub.Trim())) appDelegateCodeList += sub + "\n";
  247. }
  248. }
  249. if(!string.IsNullOrEmpty(AppDelegateLaunchCode))
  250. {
  251. string[] AppDelegates = AppDelegateLaunchCode.Split('\n');
  252. foreach(string sub in AppDelegates)
  253. {
  254. if(!appDelegateLaunchCodeList.Contains(sub.Trim())) appDelegateLaunchCodeList += sub + "\n";
  255. }
  256. }
  257. if(!string.IsNullOrEmpty(AppDelegateLaunchAsyncCode))
  258. {
  259. string[] AppDelegates = AppDelegateLaunchAsyncCode.Split('\n');
  260. foreach(string sub in AppDelegates)
  261. {
  262. if(!appDelegateLaunchAsyncCodeList.Contains(sub.Trim())) appDelegateLaunchAsyncCodeList += sub + "\n";
  263. }
  264. }
  265. if(!string.IsNullOrEmpty(AppDelegateCode))
  266. {
  267. appDelegateFunctionCodeList += "\n\n" + AppDelegateCode;
  268. }
  269. if(!string.IsNullOrEmpty(AppDelegateAdd))
  270. {
  271. appDelegateAddList += AppDelegateAdd;
  272. }
  273. }
  274. }
  275. //遍历模块文件,删除不包含的文件
  276. // string[] dirList = Directory.GetDirectories(destinationDir + "omnipotent/modules/", "*.*", SearchOption.TopDirectoryOnly);
  277. // foreach (string dir in dirList)
  278. // {
  279. // string fileName = dir.Substring(dir.LastIndexOf("/") + 1);
  280. // if(!fileIndexFiles.Contains(fileName))
  281. // Directory.Delete(dir, true);
  282. // }
  283. //添加模块文件,引用模块
  284. foreach(string fileIndexFile in fileIndexFiles)
  285. {
  286. if(fileIndexFile.StartsWith("Omega"))
  287. {
  288. customFrameworksIndex += "\n\t\t\t\t" + fileIndexFile + " = (\n" +
  289. "\t\t\t\t\tCodeSignOnCopy,\n" +
  290. "\t\t\t\t\tRemoveHeadersOnCopy,\n" +
  291. "\t\t\t\t);";
  292. customFrameworksIndexName += "\n\t\t\t\t" + fileIndexFile + ",";
  293. }
  294. }
  295. //权限CFBundleURLTypes
  296. if(!string.IsNullOrEmpty(urlTypes))
  297. {
  298. rightCodeList += "\n <key>CFBundleURLTypes</key>\n";
  299. rightCodeList += " <array>\n";
  300. rightCodeList += urlTypes;
  301. rightCodeList += " </array>";
  302. }
  303. //权限LSApplicationQueriesSchemes
  304. if(!string.IsNullOrEmpty(queriesSchemes))
  305. {
  306. rightCodeList += "\n <key>LSApplicationQueriesSchemes</key>\n";
  307. rightCodeList += " <array>\n";
  308. rightCodeList += queriesSchemes;
  309. rightCodeList += " </array>";
  310. }
  311. MakeAppCodePub.ProcessSet(ver.id);
  312. //替换项目索引信息
  313. // foreach(string fileIndexCode in fileIndexSources)
  314. // {
  315. // if(!fileIndexCode.Contains("path = Omega"))
  316. // {
  317. // projectIndexReplace += "\t\t" + fileIndexCode + "\n";
  318. // }
  319. // }
  320. // foreach(string fileIndexCode in fileIndexs)
  321. // {
  322. // projectIndexReplace += "\t\t" + fileIndexCode + "\n";
  323. // }
  324. // projectIndexReplace += "\t\t449494BB2DA4B21400486054 /* OmegaBase.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = OmegaBase.framework; sourceTree = \"<group>\"; };\n";
  325. // projectIndexReplace += endString;
  326. // projectIndexContent = projectIndexContent.Replace(projectIndexList, projectIndexReplace);
  327. projectIndexContent = projectIndexContent.Replace("/* 自定义模块 */", customFrameworksIndex);
  328. projectIndexContent = projectIndexContent.Replace("/* 自定义模块名称 */", customFrameworksIndexName);
  329. webCodeContent = webCodeContent.Replace("//模块调用代码", invokeCodeList);
  330. webCodeContent = webCodeContent.Replace("//模块方法代码", webCodeList);
  331. appDelegateCodeContent = appDelegateCodeContent.Replace("//AppDelegate引用", appDelegateCodeList);
  332. appDelegateCodeContent = appDelegateCodeContent.Replace("//AppDelegate继承代码", appDelegateAddList);
  333. appDelegateCodeContent = appDelegateCodeContent.Replace("//AppDelegate委托代码", appDelegateFunctionCodeList);
  334. appDelegateCodeContent = appDelegateCodeContent.Replace("//AppDelegate启动代码", appDelegateLaunchCodeList);
  335. appDelegateCodeContent = appDelegateCodeContent.Replace("//AppDelegate异步启动代码", appDelegateLaunchAsyncCodeList);
  336. Function.WritePageFullPath(projectIndexPath, "project.pbxproj", projectIndexContent);
  337. Function.WritePageFullPath(destinationDir + "omnipotent/", "AppConfiguration.ini", apiSet);
  338. Function.WritePageFullPath(webCodePath, "LocalWebViewController.swift", webCodeContent);
  339. Function.WritePageFullPath(appDelegateCodePath, "AppDelegate.swift", appDelegateCodeContent);
  340. MakeAppCodePub.ProcessSet(ver.id);
  341. //权限
  342. rightCodeContent = rightCodeContent.Replace("</dict>\n</plist>", rightCodeList + "</dict>\n</plist>");
  343. rightCodeContent = rightCodeContent.Replace("<string>user-login</string>", "<string>" + InitPage + "</string>");
  344. Function.WritePageFullPath(rightCodePath, "Info.plist", rightCodeContent);
  345. string toPath = destinationDir + "omnipotent/sources/";
  346. //底部导航图标下载
  347. foreach(var bottom in bottoms)
  348. {
  349. if(!string.IsNullOrEmpty(bottom.selectIcon))
  350. {
  351. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + bottom.selectIcon, toPath + "static/bottom/" + bottom.selectIcon.Substring(bottom.selectIcon.LastIndexOf("/") + 1));
  352. }
  353. if(!string.IsNullOrEmpty(bottom.normalIcon))
  354. {
  355. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + bottom.normalIcon, toPath + "static/bottom/" + bottom.normalIcon.Substring(bottom.normalIcon.LastIndexOf("/") + 1));
  356. }
  357. if(!string.IsNullOrEmpty(bottom.pagDefaultIcon))
  358. {
  359. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + bottom.pagDefaultIcon, toPath + "static/bottom/" + bottom.pagDefaultIcon.Substring(bottom.pagDefaultIcon.LastIndexOf("/") + 1));
  360. }
  361. if(!string.IsNullOrEmpty(bottom.pagLocalPath))
  362. {
  363. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + bottom.pagLocalPath, toPath + "static/bottom/" + bottom.pagLocalPath.Substring(bottom.pagLocalPath.LastIndexOf("/") + 1));
  364. }
  365. }
  366. MakeAppCodePub.ProcessSet(ver.id);
  367. //页面图标下载
  368. foreach(var page in pages)
  369. {
  370. if(page.leftBtn != null)
  371. {
  372. foreach(var btn in page.leftBtn)
  373. {
  374. if(!string.IsNullOrEmpty(btn.btnIcon))
  375. {
  376. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + btn.btnIcon, toPath + "static/page/" + btn.btnIcon.Substring(btn.btnIcon.LastIndexOf("/") + 1));
  377. }
  378. }
  379. }
  380. if (page.rightBtn != null)
  381. {
  382. foreach(var btn in page.rightBtn)
  383. {
  384. if(!string.IsNullOrEmpty(btn.btnIcon))
  385. {
  386. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + btn.btnIcon, toPath + "static/page/" + btn.btnIcon.Substring(btn.btnIcon.LastIndexOf("/") + 1));
  387. }
  388. }
  389. }
  390. }
  391. MakeAppCodePub.ProcessSet(ver.id);
  392. //解压static静态资源
  393. // string staticFilePath = Function.getPath(AppStatic);
  394. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + AppStatic, toPath + "static.zip");
  395. ZipFile.ExtractToDirectory(toPath + "static.zip", toPath, true);
  396. File.Delete(toPath + "static.zip");
  397. //生成app加密的配置文件
  398. Dictionary<string, string> appFileDic = MakeAppCodePub.getAppFile(ver, pages, bottoms, toPath);
  399. if(appFileDic.ContainsKey("AppInfoList")) Function.WritePageFullPath(destinationDir + "omnipotent/", "AppInfoList.ini", appFileDic["AppInfoList"]);
  400. if(appFileDic.ContainsKey("SystemSet")) Function.WritePageFullPath(destinationDir + "omnipotent/", "SystemSet.ini", appFileDic["SystemSet"]);
  401. if(appFileDic.ContainsKey("PageInfoList")) Function.WritePageFullPath(destinationDir + "omnipotent/", "PageInfoList.ini", appFileDic["PageInfoList"]);
  402. if(appFileDic.ContainsKey("GotoPages")) Function.WritePageFullPath(destinationDir + "omnipotent/", "GotoPages.ini", appFileDic["GotoPages"]);
  403. if(appFileDic.ContainsKey("LibFile")) Function.WritePageFullPath(destinationDir + "omnipotent/", "LibFile.ini", appFileDic["LibFile"]);
  404. //删除html文件
  405. List<string> htmlFiles = FileHelper.GetSystemFilesFromFullPath(toPath);
  406. foreach(string file in htmlFiles)
  407. {
  408. if(file.EndsWith(".html"))
  409. {
  410. File.Delete(file);
  411. }
  412. }
  413. MakeAppCodePub.ProcessSet(ver.id);
  414. //解压icon图标
  415. // string iconPath = Function.getPath(AppIcon);
  416. string toIconPath = destinationDir + "omnipotent/Assets.xcassets/";
  417. // string downloadPath = Path.GetTempPath() + "ios/" + project.id + "/";
  418. string savePath = toPath + AppIcon.Substring(AppIcon.LastIndexOf("/") + 1);
  419. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + AppIcon, savePath);
  420. ZipFile.ExtractToDirectory(savePath, toIconPath, true);
  421. File.Delete(savePath);
  422. //解压启动图
  423. // string startBgPath = Function.getPath(AppStartBg);
  424. string toStartBgPath = destinationDir + "omnipotent/Assets.xcassets/";
  425. savePath = toPath + AppStartBg.Substring(AppStartBg.LastIndexOf("/") + 1);
  426. Function.DownloadNetFile(App.OptionsSetting.OssConfigs.Host + AppStartBg, savePath);
  427. ZipFile.ExtractToDirectory(savePath, toStartBgPath, true);
  428. File.Delete(savePath);
  429. ZipFile.CreateFromDirectory(Function.getPath("applecode/" + project.id + "/"), Function.getPath("applecode/" + fileName));
  430. OssHelper.Instance.Upload(Function.getPath("applecode/" + fileName));
  431. File.Delete(Function.getPath("applecode/" + fileName));
  432. Directory.Delete(Function.getPath("applecode/" + project.id + "/"), true);
  433. MakeAppCodePub.ProcessSet(ver.id);
  434. }
  435. public static void CopyFolder(string sourceDir, string destinationDir, bool move = false)
  436. {
  437. // 如果目标文件夹不存在,则创建
  438. if (!Directory.Exists(destinationDir))
  439. {
  440. Directory.CreateDirectory(destinationDir);
  441. }
  442. // 获取源文件夹中的所有文件并复制到目标文件夹
  443. foreach (string file in Directory.GetFiles(sourceDir, "*.*", SearchOption.AllDirectories))
  444. {
  445. string destFile = file.Replace(sourceDir, destinationDir);
  446. string destDir = Path.GetDirectoryName(destFile);
  447. // 如果目标文件夹不存在,则创建
  448. if (!Directory.Exists(destDir))
  449. {
  450. Directory.CreateDirectory(destDir);
  451. }
  452. if(move)
  453. {
  454. File.Move(file, destFile, true); // 如果目标文件已存在,则覆盖
  455. }
  456. else
  457. {
  458. File.Copy(file, destFile, true); // 如果目标文件已存在,则覆盖
  459. }
  460. }
  461. // 获取源文件夹中的所有子文件夹并递归复制
  462. foreach (string dir in Directory.GetDirectories(sourceDir, "*.*", SearchOption.AllDirectories))
  463. {
  464. string destDir = dir.Replace(sourceDir, destinationDir);
  465. if (!Directory.Exists(destDir))
  466. {
  467. Directory.CreateDirectory(destDir);
  468. }
  469. }
  470. }
  471. #endregion
  472. #region 替换包名
  473. public static void ReplaceAppPackage(string destinationDir, string AppPackage)
  474. {
  475. string[] fileList = Directory.GetFiles(destinationDir, "*.*", SearchOption.AllDirectories);
  476. foreach (string file in fileList)
  477. {
  478. bool op = true;
  479. if(file.Contains(".framework") || file.Contains("Assets") || file.Contains("sources"))
  480. {
  481. op = false;
  482. }
  483. if(op)
  484. {
  485. string content = Function.ReadInstanceByFull(file);
  486. content = content.Replace("com.omega.omegamainbase", AppPackage);
  487. Function.WritePageFullPath(file.Substring(0, file.LastIndexOf("/")), file.Substring(file.LastIndexOf("/")), content);
  488. }
  489. }
  490. }
  491. #endregion
  492. }
  493. }