/// <summary> /// 根据文件清单生成压缩包 /// </summary> /// <param name="dev"></param> /// <param name="item"></param> /// <param name="type"></param> public static void GenerateCompressedPackage(bool dev, PublishDirInfo item, AppDownloadType type) { var fileEx = GetFileExByCompressedType(type); var packPath = GetPackPath(dev, item, fileEx); Console.WriteLine($"正在生成压缩包:{packPath}"); IOPath.FileIfExistsItDelete(packPath); GetCreatePackByCompressedType(type)(packPath, item.Files); using var fileStream = File.OpenRead(packPath); var sha256 = Hashs.String.SHA256(fileStream); var fileInfoM = new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length, Path = packPath, }; if (item.BuildDownloads.ContainsKey(type)) { item.BuildDownloads[type] = fileInfoM; } else { item.BuildDownloads.Add(type, fileInfoM); } }
protected override void OverwriteUpgrade(string value, bool isIncrement) { if (isIncrement) // 增量更新 { OverwriteUpgradePrivate(value); } else // 全量更新 { var dirPath = Path.Combine(AppContext.BaseDirectory, Path.GetFileNameWithoutExtension(value)); if (Directory.Exists(dirPath)) { Directory.Delete(dirPath, true); } if (TarGZipHelper.Unpack(value, dirPath, progress: new Progress <float>(OnReportDecompressing), maxProgress: MaxProgressValue)) { OnReport(MaxProgressValue); IOPath.FileTryDelete(value); OverwriteUpgradePrivate(dirPath); } else { toast.Show(SR.UpdateUnpackFail); OnReport(MaxProgressValue); } } void OverwriteUpgradePrivate(string dirPath) { OnExit(); var updateCommandPath = Path.Combine(IOPath.CacheDirectory, "update.cmd"); IOPath.FileIfExistsItDelete(updateCommandPath); var updateCommand = string.Format( SR.ProgramUpdateCmd_, AppHelper.ProgramName, dirPath.TrimEnd(Path.DirectorySeparatorChar), AppContext.BaseDirectory, AppHelper.ProgramPath); updateCommand = "chcp" + Environment.NewLine + "chcp 65001" + Environment.NewLine + updateCommand; File.WriteAllText(updateCommandPath, updateCommand, Encoding.UTF8); using var p = new Process(); p.StartInfo.FileName = updateCommandPath; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = !ThisAssembly.Debuggable; // 不显示程序窗口 p.StartInfo.Verb = "runas"; // 管理员权限运行 p.Start(); // 启动程序 } }
public static bool Handler(AppIdWithPublicKey?value, bool dev) { if (value == default) { Console.WriteLine("错误:读取剪切板值不能为 Null!"); return(false); } if (value.AppId == default) { Console.WriteLine("错误:读取剪切板值 AppId 无效!"); return(false); } if (string.IsNullOrWhiteSpace(value.PublicKey)) { Console.WriteLine("错误:读取剪切板值 PublicKey 无效!"); return(false); } var env = GetConfiguration(dev, isLower: true); var pfxFilePath = Path.Combine(projPath, $"rsa-public-key-{env}.pfx"); IOPath.FileIfExistsItDelete(pfxFilePath); File.WriteAllText(pfxFilePath, value.PublicKey); //var appIdFilePath = Path.Combine(projPath, // $"app-id-{env}.pfx"); //IOPath.FileIfExistsItDelete(appIdFilePath); //File.WriteAllBytes(appIdFilePath, value.AppId.ToByteArray()); Console.WriteLine(pfxFilePath); //Console.WriteLine(appIdFilePath); return(true); }
public static void Add(RootCommand command) { var rmci = new Command("read_msal_client_id", "读取 MSALClientId 写入txt的pfx文件中"); rmci.AddAlias("rmci"); rmci.AddOption(new Option <string>("-val", () => string.Empty, "通过命令行将值传入")); rmci.Handler = CommandHandler.Create((string val) => { if (string.IsNullOrWhiteSpace(val)) { var text = ClipboardService.GetText(); if (string.IsNullOrWhiteSpace(text)) { Console.WriteLine("错误:读取剪切板值无效!"); return; } else { val = text; } } if (!Guid.TryParse(val, out var guid)) { Console.WriteLine("错误:值无效!"); return; } var filePath = Path.Combine(projPath, "masl-client-id.pfx"); IOPath.FileIfExistsItDelete(filePath); File.WriteAllBytes(filePath, guid.ToByteArray()); Console.WriteLine("完成。"); Console.WriteLine(filePath); }); command.AddCommand(rmci); }
static IList <string>?ReadXlsx(CommandArguments args) { List <string> messages = new(); var resxFilePathLang = GetResxFilePathLang(args); var excelFilePath = GetXlsxFilePath(resxFilePathLang, args.lang); using var fs = File.OpenRead(excelFilePath); var workbook = new XSSFWorkbook(fs); if (workbook.NumberOfSheets <= 0) { return(messages); } var sheet = workbook.GetSheetAt(0); IRow row; ICell cell; int index_row = 0, index_cell = 0; do // 定位 Header { row = sheet.GetRow(index_row++); if (row == null) { return(messages); } cell = row.GetCell(0); } while (!cell.StringCellValue.Contains(ColumnHeaderKey)); int index_cell_value = -1, index_cell_author = -1, index_cell_comment = -1, index_cell_value_machine = -1; while (true) // 定位 Value Cell Index { var cellnum = index_cell++; cell = row.GetCell(cellnum); if (cell == null) { break; } if (cell.StringCellValue.Contains(ColumnHeaderMachineTranslation)) { index_cell_value_machine = cellnum; } if (cell.StringCellValue.Contains(ColumnHeaderHumanTranslation)) { index_cell_value = cellnum; } if (cell.StringCellValue.Contains(ColumnHeaderAuthor)) { index_cell_author = cellnum; } if (cell.StringCellValue.Contains(ColumnHeaderComment)) { index_cell_comment = cellnum; } } if (index_cell_value == -1 || index_cell_author == -1 || index_cell_comment == -1) { return(messages); } Dictionary <string, (string value, Dictionary <string, string> comment)> dict = new(); while (true) // 循环 Body 区域 { row = sheet.GetRow(index_row++); if (row == null) { break; } var keyCell = row.GetCell(0); var valueCell = row.GetCell(index_cell_value); var valueMachineCell = index_cell_value_machine != -1 ? row.GetCell(index_cell_value_machine) : null; var commentCell = row.GetCell(index_cell_comment); var authorCell = row.GetCell(index_cell_author); var key = keyCell.StringCellValue; var value = (valueCell ?? valueMachineCell)?.StringCellValue; var comment = commentCell.StringCellValue; var author = authorCell.StringCellValue; if (!string.IsNullOrWhiteSpace(value)) { var commentDict = new Dictionary <string, string> { { CommentKey, comment }, { AuthorKey, author }, }; dict.Add(key, (value, commentDict)); } } var resxFileDictLangDict = GetResxDict2(resxFilePathLang, ignoreStringBuilder: true).dict; foreach (var item in dict) { resxFileDictLangDict.AddOrReplace(item); } var template = Properties.Resources.Resx; const string rootEndMark = "</root>"; var rootEndIndex = template.IndexOf(rootEndMark); if (rootEndIndex == -1) { messages.Add("template.IndexOf(\"</root>\") == -1"); return(messages); } var sb = new StringBuilder(template.Substring(0, rootEndIndex)); foreach (var item in resxFileDictLangDict) { sb.AppendFormatLine(" <data name=\"{0}\" xml:space=\"preserve\">", item.Key); sb.AppendFormatLine(" <value>{0}</value>", Escape(item.Value.value)); var commentStr = Serialize(item.Value.comment); if (!string.IsNullOrWhiteSpace(commentStr)) { sb.AppendFormatLine(" <comment>{0}</comment>", Escape(commentStr)); } sb.AppendLine(" </data>"); } sb.AppendLine(rootEndMark); var str = sb.ToString(); IOPath.FileIfExistsItDelete(resxFilePathLang); File.WriteAllText(resxFilePathLang, str); return(messages); }
static PublishDirInfo[]? Handler(DeploymentMode d, string[] val, bool dev) { if (!val.Any_Nullable()) { Console.WriteLine(InputPubDirNameError); return(null); } var pubPath = d switch { DeploymentMode.SCD => DirPublish_, DeploymentMode.FDE => DirPublish_FDE_, _ => throw new ArgumentOutOfRangeException(nameof(d), d, null), }; var dirBasePath = projPath + string.Format(pubPath, GetConfiguration(dev, isLower: false)); var dirNames = val.Select(x => new PublishDirInfo(x, Path.Combine(dirBasePath, x), d)).Where(x => Directory.Exists(x.Path)).ToArray(); var publish_json_path = PublishJsonFilePath; IOPath.FileIfExistsItDelete(publish_json_path); foreach (var item in dirNames) { var isMacOS = item.Name.StartsWith("osx"); // ASP.NET Core Runtime 6.0.0 缺少 macOS Installers if (isMacOS && d == DeploymentMode.FDE) { continue; } if (!Directory.Exists(item.Path)) { Console.WriteLine($"错误:找不到发布文件夹({item.Name}),{item.Path}"); return(null); } List <Action> lazyActions = new(); lazyActions.Add(() => { ScanPath(item.Path, item.Files, ignoreRootDirNames: ignoreDirNames); }); //if (item.Name.StartsWith("win", StringComparison.OrdinalIgnoreCase)) //{ // #region 适用于 Windwos 7 OS 的 疑难解答助手 // string win7Path; // if (IsAigioPC) // { // win7Path = @"G:\Steam++.Win7"; // } // else // { // win7Path = Path.Combine(item.Path, "..", "Steam++.Win7"); // } // var win7ExePath = Path.Combine(win7Path, "Steam++.Win7.exe"); // if (!File.Exists(win7ExePath) || !File.Exists(win7ExePath + ".config")) // { // Console.WriteLine($"错误:Win7疑难助手程序不存在!{win7ExePath}"); // return; // } // lazyActions.Add(() => // { // ScanPath(win7Path, item.Files); // }); // #endregion // var consoleExeFileName = Path.Combine(item.Path, "Steam++.Console.exe"); // if (!File.Exists(consoleExeFileName)) // { // Console.WriteLine($"错误:Steam++.Console.exe 不存在!"); // return; // } //} //if (item.Name.Equals("win-x86", StringComparison.OrdinalIgnoreCase)) //{ // #region Win10SDK.NET // const string netSDKFileName = "Microsoft.Windows.SDK.NET.dll"; // var netSDKFileRefPath = Path.Combine(projPath, "references", netSDKFileName); // if (!File.Exists(netSDKFileRefPath)) // { // Console.WriteLine($"错误:Microsoft.Windows.SDK.NET.dll不存在!{netSDKFileRefPath}"); // return; // } // var netSDKFileRefInfoVersion = GetInfoVersion(netSDKFileRefPath); // var netSDKFilePath = Path.Combine(item.Path, netSDKFileName); // var netSDKFileInfoVersion = GetInfoVersion(netSDKFilePath); // if (netSDKFileRefInfoVersion != netSDKFileInfoVersion) // { // Console.WriteLine("错误:Microsoft.Windows.SDK.NET.dll 版本不正确!"); // Console.WriteLine($"Version: {netSDKFileInfoVersion}"); // Console.WriteLine($"Version(Ref): {netSDKFileRefInfoVersion}"); // return; // } // lazyActions.Add(() => // { // foreach (var file in item.Files) // { // if (file.Path == netSDKFilePath) // { // file.Path = netSDKFileRefPath; // file.Length = new FileInfo(netSDKFileRefPath).Length; // } // } // }); // #endregion //} //string cefRootPath; //if (IsAigioPC) //{ // cefRootPath = @"G:\"; //} //else //{ // cefRootPath = Path.Combine(item.Path, ".."); //} //var cefPath = Path.Combine(cefRootPath, "CEF", item.Name); //if (!Directory.Exists(cefPath)) //{ // Console.WriteLine($"错误:CEF库文件夹不存在!{cefPath}"); // return; //} //else if (!Directory.GetFiles(cefPath).Any()) //{ // Console.WriteLine($"错误:CEF库文件不存在!{cefPath}"); // return; //} //lazyActions.Add(() => //{ // ScanPath(cefPath, item.Files, cefRootPath); //}); lazyActions.ForEach(x => x()); Console.WriteLine($"{item.Name}, count: {item.Files.Count}"); if (calcHash) { foreach (var file in item.Files) { Console.WriteLine($"正在计算哈希值:{file.Path}"); using var fileStream = File.OpenRead(file.Path); file.SHA256 = Hashs.String.SHA256(fileStream); } } } return(dirNames); }