// 创建 Windows 存储事件日志的文件 static int MakeWindowsLogFile(EventLog log, string strEventLogFilename, DispInfo procDispInfo, out string strError) { strError = ""; int nLines = 0; try { if (procDispInfo != null) { procDispInfo("正在准备 Windows 事件日志 " + log.LogDisplayName + "..."); } using (StreamWriter sw = new StreamWriter(strEventLogFilename, false, Encoding.UTF8)) { foreach (EventLogEntry entry in log.Entries) { #if NO Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return(-1); } #endif if (procDispInfo != null) { if (procDispInfo(null) == false) { strError = "用户中断"; return(-1); } } // 过滤出只和 dp2circulation 有关的 string strMessageText = entry.Message.ToLower(); if (strMessageText.IndexOf("dp2circulation") != -1) { string strText = "*\r\n" + entry.Source + " \t" + entry.EntryType.ToString() + " \t" + entry.TimeGenerated.ToString() + "\r\n" + entry.Message + "\r\n\r\n"; sw.Write(strText); nLines++; } } } } catch (Exception ex) { strError = "输出 Windows 日志 " + log.LogDisplayName + "的信息时出现异常: " + ex.Message; return(-1); } return(nLines); }
void Start() { worldMgr = GameObject.Find("WorldMap").GetComponent <WorldManager>(); if (dispInfo == null) { dispInfo = new DispInfo(); } if (!worldMgr.isReady) { Target_DispMapGeneratorPanel(connectionToClient, worldMgr.loadExistMapList().ToArray()); } else { BroadcastNewMap(worldMgr.worldData.width, worldMgr.worldData.height); player.TopMenu.SetActive(true); } }
// parameters: // strDataDir 存储需要打包数据的目录。即 dp2circulation 用户目录 // strTempDir 临时目录。本方法要先清空这个目录,所以应该提供一个专用临时目录 public static int Package(List <EventLog> logs, string strZipFileName, string strRangeName, string strDataDir, string strTempDir, DispInfo procDispInfo, out string strError) { strError = ""; int nRet = 0; PathUtil.TryClearDir(strTempDir); List <string> filenames = new List <string>(); foreach (EventLog log in logs) { // 创建 eventlog_digitalplatform.txt 文件 string strEventLogFilename = Path.Combine(strTempDir, "eventlog_" + log.LogDisplayName + ".txt"); // // nRet = MakeWindowsLogFile(log, strEventLogFilename, procDispInfo, out strError); if (nRet == -1) { return(-1); } if (nRet > 0) { filenames.Add(strEventLogFilename); } else { File.Delete(strEventLogFilename); } } // 创建一个描述了安装的各个实例和环境情况的文件 string strDescriptionFilename = Path.Combine(strTempDir, "description.txt"); try { if (procDispInfo != null) { procDispInfo("正在准备 description.txt 文件 ..."); } using (StreamWriter sw = new StreamWriter(strDescriptionFilename, false, Encoding.UTF8)) { sw.Write(GetEnvironmentDescription()); } } catch (Exception ex) { strError = "输出 description.txt 时出现异常: " + ex.Message; return(-1); } filenames.Add(strDescriptionFilename); // TODO: 是否复制整个数据目录? 需要避免复制日志文件和其他尺寸很大的文件 // 复制错误日志文件和其他重要文件 List <string> dates = MakeDates(strRangeName); // "最近31天""最近十年""最近七天" // *** dp2library 各个 instance string strInstanceDir = Path.Combine(strTempDir, "log"); PathUtil.TryCreateDir(strInstanceDir); foreach (string date in dates) { #if NO Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return(-1); } #endif if (procDispInfo != null) { if (procDispInfo(null) == false) { strError = "用户中断"; return(-1); } } string strFilePath = Path.Combine(strDataDir, "log/log_" + date + ".txt"); if (File.Exists(strFilePath) == false) { continue; } string strTargetFilePath = Path.Combine(strInstanceDir, "log_" + date + ".txt"); if (procDispInfo != null) { procDispInfo("正在复制文件 " + strFilePath); } File.Copy(strFilePath, strTargetFilePath); filenames.Add(strTargetFilePath); } if (filenames.Count == 0) { return(0); } if (filenames.Count > 0) { // bool bRangeSetted = false; using (ZipFile zip = new ZipFile(Encoding.UTF8)) { // http://stackoverflow.com/questions/15337186/dotnetzip-badreadexception-on-extract // https://dotnetzip.codeplex.com/workitem/14087 // uncommenting the following line can be used as a work-around zip.ParallelDeflateThreshold = -1; foreach (string filename in filenames) { #if NO Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return(-1); } #endif if (procDispInfo != null) { if (procDispInfo(null) == false) { strError = "用户中断"; return(-1); } } string strShortFileName = filename.Substring(strTempDir.Length + 1); if (procDispInfo != null) { procDispInfo("正在压缩 " + strShortFileName); } string directoryPathInArchive = Path.GetDirectoryName(strShortFileName); zip.AddFile(filename, directoryPathInArchive); } if (procDispInfo != null) { procDispInfo("正在写入压缩文件 ..."); } #if NO zip.SaveProgress += (s, e) => { Application.DoEvents(); if (stop != null && stop.State != 0) { e.Cancel = true; return; } if (e.EventType == ZipProgressEventType.Saving_AfterWriteEntry) { if (bRangeSetted == false) { stop.SetProgressRange(0, e.EntriesTotal); bRangeSetted = true; } stop.SetProgressValue(e.EntriesSaved); } }; #endif zip.UseZip64WhenSaving = Zip64Option.AsNecessary; zip.Save(strZipFileName); #if NO stop.HideProgress(); if (stop != null && stop.State != 0) { strError = "用户中断"; return(-1); } #endif } if (procDispInfo != null) { procDispInfo("正在删除中间文件 ..."); } // 删除原始文件 foreach (string filename in filenames) { File.Delete(filename); } // 删除三个子目录 PathUtil.DeleteDirectory(Path.Combine(strTempDir, "log")); } return(0); }
// parameters: // strDataDir 存储需要打包数据的目录。即 dp2circulation 用户目录 // strTempDir 临时目录。本方法要先清空这个目录,所以应该提供一个专用临时目录 public static int Package(List<EventLog> logs, string strZipFileName, string strRangeName, string strDataDir, string strTempDir, DispInfo procDispInfo, out string strError) { strError = ""; int nRet = 0; PathUtil.ClearDir(strTempDir); List<string> filenames = new List<string>(); foreach (EventLog log in logs) { // 创建 eventlog_digitalplatform.txt 文件 string strEventLogFilename = Path.Combine(strTempDir, "eventlog_" + log.LogDisplayName + ".txt"); // // nRet = MakeWindowsLogFile(log, strEventLogFilename, procDispInfo, out strError); if (nRet == -1) return -1; if (nRet > 0) filenames.Add(strEventLogFilename); else File.Delete(strEventLogFilename); } // 创建一个描述了安装的各个实例和环境情况的文件 string strDescriptionFilename = Path.Combine(strTempDir, "description.txt"); try { if (procDispInfo != null) procDispInfo("正在准备 description.txt 文件 ..."); using (StreamWriter sw = new StreamWriter(strDescriptionFilename, false, Encoding.UTF8)) { sw.Write(GetEnvironmentDescription()); } } catch (Exception ex) { strError = "输出 description.txt 时出现异常: " + ex.Message; return -1; } filenames.Add(strDescriptionFilename); // TODO: 是否复制整个数据目录? 需要避免复制日志文件和其他尺寸很大的文件 // 复制错误日志文件和其他重要文件 List<string> dates = MakeDates(strRangeName); // "最近31天""最近十年""最近七天" // *** dp2library 各个 instance string strInstanceDir = Path.Combine(strTempDir, "log"); PathUtil.CreateDirIfNeed(strInstanceDir); foreach (string date in dates) { #if NO Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } #endif if (procDispInfo != null) { if (procDispInfo(null) == false) { strError = "用户中断"; return -1; } } string strFilePath = Path.Combine(strDataDir, "log/log_" + date + ".txt"); if (File.Exists(strFilePath) == false) continue; string strTargetFilePath = Path.Combine(strInstanceDir, "log_" + date + ".txt"); if (procDispInfo != null) procDispInfo("正在复制文件 " + strFilePath); File.Copy(strFilePath, strTargetFilePath); filenames.Add(strTargetFilePath); } if (filenames.Count == 0) return 0; if (filenames.Count > 0) { // bool bRangeSetted = false; using (ZipFile zip = new ZipFile(Encoding.UTF8)) { foreach (string filename in filenames) { #if NO Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } #endif if (procDispInfo != null) { if (procDispInfo(null) == false) { strError = "用户中断"; return -1; } } string strShortFileName = filename.Substring(strTempDir.Length + 1); if (procDispInfo != null) procDispInfo("正在压缩 " + strShortFileName); string directoryPathInArchive = Path.GetDirectoryName(strShortFileName); zip.AddFile(filename, directoryPathInArchive); } if (procDispInfo != null) procDispInfo("正在写入压缩文件 ..."); #if NO zip.SaveProgress += (s, e) => { Application.DoEvents(); if (stop != null && stop.State != 0) { e.Cancel = true; return; } if (e.EventType == ZipProgressEventType.Saving_AfterWriteEntry) { if (bRangeSetted == false) { stop.SetProgressRange(0, e.EntriesTotal); bRangeSetted = true; } stop.SetProgressValue(e.EntriesSaved); } }; #endif zip.UseZip64WhenSaving = Zip64Option.AsNecessary; zip.Save(strZipFileName); #if NO stop.HideProgress(); if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } #endif } if (procDispInfo != null) procDispInfo("正在删除中间文件 ..."); // 删除原始文件 foreach (string filename in filenames) { File.Delete(filename); } // 删除三个子目录 PathUtil.DeleteDirectory(Path.Combine(strTempDir, "log")); } return 0; }
// 创建 Windows 存储事件日志的文件 static int MakeWindowsLogFile(EventLog log, string strEventLogFilename, DispInfo procDispInfo, out string strError) { strError = ""; int nLines = 0; try { if (procDispInfo != null) procDispInfo("正在准备 Windows 事件日志 " + log.LogDisplayName + "..."); using (StreamWriter sw = new StreamWriter(strEventLogFilename, false, Encoding.UTF8)) { foreach (EventLogEntry entry in log.Entries) { #if NO Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } #endif if (procDispInfo != null) { if (procDispInfo(null) == false) { strError = "用户中断"; return -1; } } // 过滤出只和 dp2circulation 有关的 string strMessageText = entry.Message.ToLower(); if (strMessageText.IndexOf("dp2circulation") != -1) { string strText = "*\r\n" + entry.Source + " \t" + entry.EntryType.ToString() + " \t" + entry.TimeGenerated.ToString() + "\r\n" + entry.Message + "\r\n\r\n"; sw.Write(strText); nLines++; } } } } catch (Exception ex) { strError = "输出 Windows 日志 " + log.LogDisplayName + "的信息时出现异常: " + ex.Message; return -1; } return nLines; }