static void t1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { if (!Directory.Exists(ConfigHandler.instance.tempfolder)) { Directory.CreateDirectory(ConfigHandler.instance.tempfolder); } DateTime dt = DateTime.Now; string fileName = String.Concat(dt.Hour, dt.Minute, dt.Second, dt.Day, dt.Month, dt.Year, ConfigHandler.instance.imageExtension); string tmpFileName = Path.Combine(ConfigHandler.instance.systemTempFolder, fileName); ImageHelper.GetCurrentScreen().Save(tmpFileName, ImageFormat.Jpeg); string tmpPackageName = AssignName(dt); if (!tmpPackageName.Equals(zipFile)) { zipFile = tmpPackageName; } ZipHelper z = new ZipHelper(); z.AddFilesToZip(zipFile, ConfigHandler.instance.systemTempFolder, fileName, false, "pepe"); if (File.Exists(tmpFileName)) { File.Delete(tmpFileName); } } catch (Exception ex) { ex.ToString(); } }
private static bool Do(string nugetPackageFilePath) { if (string.IsNullOrWhiteSpace(nugetPackageFilePath)) { return(false); } if (!File.Exists(nugetPackageFilePath)) { Console.WriteLine($"未找到nuget包:{nugetPackageFilePath}"); return(false); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(nugetPackageFilePath); Console.ForegroundColor = ConsoleColor.White; var addFileList = new List <ContentToZip>(); var xmlNodeList = XmlHelper.GetXmlNodeList(_xmlFilePath, $"{_xpathBase}/addFiles/file"); if (xmlNodeList != null) { foreach (XmlNode xmlNode in xmlNodeList) { if (xmlNode.Attributes != null) { var path = Path.Combine(_baseDir, xmlNode.Attributes["path"]?.Value ?? string.Empty); var target = xmlNode.Attributes["target"]?.Value; if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) { Console.WriteLine($"文件不存在:{path}"); return(false); } Console.WriteLine($"{path} => {target}"); addFileList.Add(new ContentToZip { Path = path, RelativeFolder = target }); } } } if (addFileList.Count < 1) { Console.WriteLine("没有文件需要添加"); return(false); } // nuget包添加文件 return(ZipHelper.AddFilesToZip(nugetPackageFilePath, addFileList)); }