public static Icon GetIcon(String name) { try { var src = FileSource.GetFileResource(null, "leaf.png"); if (src == null) { return(null); } using (var bmp = new Bitmap(src)) { using (var water = MakeWater(bmp, name, true)) { var ms = new MemoryStream(); IconFile.Convert(water, ms, new Int32[] { 32 }, new Int32[] { 32 }); ms.Position = 0; return(new Icon(ms)); } } } catch { return(null); } }
public FrmText() { InitializeComponent(); this.Icon = FileSource.GetIcon(); }
public void Update() { // 取版本 // 对比版本 // 拿出更新源 // 下载更新包 // 执行更新 #region 准备工作 var curdir = AppDomain.CurrentDomain.BaseDirectory; String ProcessHelper = Path.Combine(curdir, "NewLife.ProcessHelper.exe"); if (File.Exists(ProcessHelper)) { File.Delete(ProcessHelper); } // 删除Update目录,避免重复使用错误的升级文件 var update = Path.Combine(curdir, "Update"); if (Directory.Exists(update)) { try { Directory.Delete(update, true); } catch { } } var updatebat = Path.Combine(curdir, "Update.bat"); if (File.Exists(updatebat)) { try { File.Delete(updatebat); } catch { } } // 开发环境下,自动生成版本文件 if (IsDevelop()) { MakeVerFile(); } #endregion #region 取版本、对比版本 var client = new WebClientX(); client.Encoding = Encoding.UTF8; // 同步下载,3秒超时 client.Timeout = 3000; XTrace.WriteLine("准备从{0}下载版本文件!", VerSrc); String xml = client.DownloadString(VerSrc); if (String.IsNullOrEmpty(xml)) { XTrace.WriteLine("无法从{0}获取版本信息!", VerSrc); return; } var ver = new VerFile(xml); var asm = Assembly.GetExecutingAssembly(); if (asm.GetName().Version >= ver.GetVersion()) { return; } #endregion #region 提示更新 { var sb = new StringBuilder(); sb.AppendFormat("是否更新到最新版本:{0}", ver.Ver); sb.AppendLine(); sb.AppendLine("XCoder会自动关闭以进行更新,更新完成后会启动新版本!"); if (!String.IsNullOrEmpty(ver.Description)) { sb.AppendLine("更新内容:"); sb.Append(ver.Description); } if (MessageBox.Show(sb.ToString(), "发现新版本", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } } #endregion #region 载 String file = Path.Combine(update, "XCoder.zip"); CheckAndDownload(client, file, ver.Src); // 检查是否需要更新源码 String xfile = Path.Combine(@"C:\X\Src", "Src.zip"); String dfile = Path.Combine(@"C:\X\DLL", "DLL.zip"); CheckAndDownload(client, xfile, ver.XSrc); CheckAndDownload(client, dfile, ver.DLL); #endregion #region 更新 // 先更新源代码 Extract(xfile, null); Extract(dfile, null); var dir = Path.GetDirectoryName(file); if (Extract(file, dir)) { var cfgfile = Path.Combine(curdir, "XCoder.exe.config"); var xmlfile = Path.Combine(curdir, "XCoder.xml"); var sb = new StringBuilder(); // 备份配置文件 sb.AppendFormat("mov \"{0}\" \"{0}.bak\" /Y", cfgfile); sb.AppendFormat("mov \"{0}\" \"{0}.bak\" /Y", xmlfile); // 复制 sb.AppendFormat("copy \"{0}\\*.*\" \"{1}\" /y", dir, curdir); sb.AppendLine(); sb.AppendLine("rd \"" + dir + "\" /s /q"); // 还原配置文件 sb.AppendFormat("mov \"{0}.bak\" \"{0}\" /Y", cfgfile); sb.AppendFormat("mov \"{0}.bak\" \"{0}\" /Y", xmlfile); // 启动XCoder sb.AppendFormat("start {0}", Path.GetFileName(Application.ExecutablePath)); sb.AppendLine(); // 删除dir目录 //sb.AppendLine("rd \"" + dir + "\" /s /q"); sb.AppendFormat("del \"{0}\" /f/q", ProcessHelper); sb.AppendLine(); sb.AppendFormat("del \"{0}\" /f/q", updatebat); sb.AppendLine(); //String tmpfile = Path.GetTempFileName() + ".bat"; //String tmpfile = "Update.bat"; File.WriteAllText(updatebat, sb.ToString(), Encoding.Default); #region 老树修改 // FileSource.ReleaseFile("XCoder.NewLife.ProcessHelper.exe", ProcessHelper); //修改部分 string assemFullName = Assembly.GetExecutingAssembly().FullName; string assemNamespace = assemFullName.Substring(0, assemFullName.IndexOf(',')); //命名空间名称 FileSource.ReleaseFile(assemNamespace + ".NewLife.ProcessHelper.exe", ProcessHelper); #endregion ProcessStartInfo si = new ProcessStartInfo(); si.FileName = ProcessHelper; si.WorkingDirectory = Path.GetDirectoryName(si.FileName); si.Arguments = Process.GetCurrentProcess().Id + " " + updatebat; if (!XTrace.Debug) { si.CreateNoWindow = true; si.WindowStyle = ProcessWindowStyle.Hidden; } si.UseShellExecute = false; Process.Start(si); XTrace.WriteLine("已启动进程助手来升级,升级脚本:{0}", updatebat); Application.Exit(); } #endregion }