⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formmain.cs

📁 kuiMsg是一款用.net C# 开发的即时消息开源软件,适合.net即时消息软件开发者用。 主要功能: 支持文件传输(p2p); 支持GIF动画表情( 彻底消除闪屏 :) );
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace LanMsgUpdate
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class FormMain : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label labelState;
        private Timer timer1;
        private IContainer components;

		public FormMain()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.labelState = new System.Windows.Forms.Label();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.labelState);
            this.groupBox1.Location = new System.Drawing.Point(10, 7);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(279, 63);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "升级状态";
            this.groupBox1.UseWaitCursor = true;
            // 
            // labelState
            // 
            this.labelState.AutoSize = true;
            this.labelState.Location = new System.Drawing.Point(8, 23);
            this.labelState.Name = "labelState";
            this.labelState.Size = new System.Drawing.Size(107, 12);
            this.labelState.TabIndex = 0;
            this.labelState.Text = "正在安装升级包...";
            this.labelState.UseWaitCursor = true;
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 3000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // FormMain
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(299, 78);
            this.ControlBox = false;
            this.Controls.Add(this.groupBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Name = "FormMain";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "LanMsg 智能更新程序";
            this.TopMost = true;
            this.UseWaitCursor = true;
            this.Load += new System.EventHandler(this.FormMain_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new FormMain());
		}

		private void FormMain_Load(object sender, System.EventArgs e)
		{
             
		}

		private void KillLanMsgProcess()//关闭所有正在运行的LanMsg进程
		{
			System.Diagnostics.Process[] pTemp = System.Diagnostics.Process.GetProcesses();
			foreach(System.Diagnostics.Process pTempProcess in pTemp)
				if ((pTempProcess.ProcessName.ToLower() == ("LanMsg").ToLower()) || (pTempProcess.ProcessName.ToLower()) == ("LanMsg.exe").ToLower()) 
				   pTempProcess.Kill();
		}

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.timer1.Enabled = false;
            this.labelState.Text = "正在终止LanMsg的运行...";//\n提示:此次升级后需要重新输入用户与密码登录
            this.labelState.Refresh();
            KillLanMsgProcess();//关闭所有正在运行的LanMsg进程
            System.Threading.Thread.Sleep(10000);
            this.labelState.Text = "正在更新升级包...";
            this.labelState.Refresh();
            DeCompress("LanMsg.exe");//将新版本的LanMsg文件写入当前目录,并运行新版本的应用程序
            DeCompress("IMLibrary.dll");//将新版本的LanMsg文件写入当前目录,并运行新版本的应用程序

            this.labelState.Text = "正在启动LanMsg...";
            this.labelState.Refresh();
            System.Diagnostics.Process.Start(Application.StartupPath + "\\LanMsg.exe");//运行刚更新的应用程序

            
            Application.Exit();
        }

		private void DeCompress(string resourceName)//将资源文件写入当前目录
		{
            string TempFile = Application.StartupPath + "\\" + resourceName;// ;
       
			if(System.IO.File.Exists(TempFile))//删除当前目录低版本的 LanMsg
				System.IO.File.Delete(TempFile);

			byte[] b=new byte[1];

			if(!System.IO.File.Exists(TempFile))
			{
                System.IO.Stream tobjStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsgUpdate." + resourceName);
				System.IO.Stream f =new System.IO.FileStream(TempFile, System.IO.FileMode.CreateNew);
				long fLength=tobjStream.Length;
				for(int i=0;i<fLength;i++)
				{
					tobjStream.Read(b,0,1);
					f.WriteByte(b[0]) ;
				}
				f.Flush();
				f.Close();
				tobjStream.Close();
			}
		}

 
         
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -