我的更新程序的使用方法(program 下编辑的启动操作)

入口文件的操作

 /// 
        /// 应用程序的主入口点。
        /// 
        [STAThread]
        static void Main(string[] Arg)//如果是使用有参数则是源文件登录,如果没有带参数先进入更新程序,查询完了再登录
        {
            #region 全局异常注册
            if (Arg == null || Arg.Length ==0 )
            {
                string UpdateSoftAt = Application.StartupPath + "\\Tools\\UpdateSoft\\UpdateSoft.exe";
                if (File.Exists(UpdateSoftAt))//如果存在就直接更新
                {
                    string GuidStr = "";
                    Assembly assem = Assembly.GetExecutingAssembly();
                    Type type = typeof(System.Runtime.InteropServices.GuidAttribute);
                    foreach (GuidAttribute guid in assem.GetCustomAttributes(type, false))
                    {
                        GuidStr = guid.Value;//本地软件Guid
                    }
                    string SoftVal = Assembly.GetExecutingAssembly().GetName().Version.ToString();//本地软件版本
                    string LocalPath = assem.Location; //本地软件地址
                    string CanshuOut = $"{GuidStr} {SoftVal} {LocalPath}";
                    System.Diagnostics.Process.Start(UpdateSoftAt, CanshuOut);
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                    Application.Exit();
                    System.Environment.Exit(0);
                }
            }  
            Application.ThreadException += Application_ThreadException; //UI线程异常
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //多线程异常
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            #endregion
            bool ret;
            Mutex mutex = new Mutex(true, Application.ProductName, out ret);//重复启动检测
            if (ret)
            {
                FrmLogin frm = new FrmLogin();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new FormShowMain());
                }
            }
            else
            {
                MessageBox.Show("该程序已经启动", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;
            //WriteLog(ex.Message);
            OPCommon.LogWrite.WriteLog(ex.Message + ex.StackTrace);
            MessageBox.Show(string.Format("捕获到未处理异常:{0}\r\n异常信息:{1}\r\n异常堆栈:{2}\r\nCLR即将退出:{3}", ex.GetType(), ex.Message, ex.StackTrace, e.IsTerminating));
        }
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Exception ex = e.Exception;
            //WriteLog(ex.Message);
            OPCommon.LogWrite.WriteLog(ex.Message + ex.StackTrace);
            MessageBox.Show(string.Format("捕获到未处理异常:{0}\r\n异常信息:{1}\r\n异常堆栈:{2}", ex.GetType(), ex.Message, ex.StackTrace));
        }
    }

升级数据库的操作 两个表格:
一个是日志表格,一个是更新文件表格

USE [master]
GO
/****** Object:  Database [UpdateFilesDB]    Script Date: 10/21/2023 16:54:56 ******/
CREATE DATABASE [UpdateFilesDB] ON  PRIMARY 
( NAME = N'UpdateFilesDB', FILENAME = N'D:\DB\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\UpdateFilesDB.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'UpdateFilesDB_log', FILENAME = N'D:\DB\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\UpdateFilesDB_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [UpdateFilesDB] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [UpdateFilesDB].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [UpdateFilesDB] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [UpdateFilesDB] SET ANSI_NULLS OFF
GO
ALTER DATABASE [UpdateFilesDB] SET ANSI_PADDING OFF
GO
ALTER DATABASE [UpdateFilesDB] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [UpdateFilesDB] SET ARITHABORT OFF
GO
ALTER DATABASE [UpdateFilesDB] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [UpdateFilesDB] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [UpdateFilesDB] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [UpdateFilesDB] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [UpdateFilesDB] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [UpdateFilesDB] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [UpdateFilesDB] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [UpdateFilesDB] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [UpdateFilesDB] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [UpdateFilesDB] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [UpdateFilesDB] SET  DISABLE_BROKER
GO
ALTER DATABASE [UpdateFilesDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [UpdateFilesDB] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [UpdateFilesDB] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [UpdateFilesDB] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [UpdateFilesDB] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [UpdateFilesDB] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [UpdateFilesDB] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [UpdateFilesDB] SET  READ_WRITE
GO
ALTER DATABASE [UpdateFilesDB] SET RECOVERY FULL
GO
ALTER DATABASE [UpdateFilesDB] SET  MULTI_USER
GO
ALTER DATABASE [UpdateFilesDB] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [UpdateFilesDB] SET DB_CHAINING OFF
GO
EXEC sys.sp_db_vardecimal_storage_format N'UpdateFilesDB', N'ON'
GO
USE [UpdateFilesDB]
GO
/****** Object:  User [Yinyu]    Script Date: 10/21/2023 16:54:56 ******/
CREATE USER [Yinyu] FOR LOGIN [Yinyu] WITH DEFAULT_SCHEMA=[dbo]
GO
/****** Object:  Table [dbo].[SoftUpTB]    Script Date: 10/21/2023 16:54:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SoftUpTB](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[SoftGuid] [nvarchar](80) NULL,
	[SoftVersion] [nvarchar](50) NULL,
	[Url] [nvarchar](200) NULL,
	[FileType] [int] NULL,
	[SoftName] [nvarchar](120) NULL,
	[Remak] [nvarchar](100) NULL,
	[CreateDate] [datetime] NULL
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'软件指纹GUID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'SoftGuid'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'当前软件版本' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'SoftVersion'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'保存地址' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'Url'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'文件类型(0是压缩文件,1是 裸文件)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'FileType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'软件名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'SoftName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'Remak'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB', @level2type=N'COLUMN',@level2name=N'CreateDate'
GO
EXEC sys.sp_addextendedproperty @name=N'Name', @value=N'更新表格' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpTB'
GO
/****** Object:  Table [dbo].[SoftUpLog]    Script Date: 10/21/2023 16:54:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SoftUpLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[ClientVersion] [nvarchar](50) NULL,
	[ClientPCName] [nvarchar](100) NULL,
	[ClientIP] [nvarchar](50) NULL,
	[UpdateTBId] [int] NULL,
	[CreateDate] [datetime] NULL
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户端当前版本' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpLog', @level2type=N'COLUMN',@level2name=N'ClientVersion'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户端计算机名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpLog', @level2type=N'COLUMN',@level2name=N'ClientPCName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户端Ip' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpLog', @level2type=N'COLUMN',@level2name=N'ClientIP'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'更新文件Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpLog', @level2type=N'COLUMN',@level2name=N'UpdateTBId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'操作时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpLog', @level2type=N'COLUMN',@level2name=N'CreateDate'
GO
EXEC sys.sp_addextendedproperty @name=N'Name', @value=N'更新日志' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SoftUpLog'
GO
/****** Object:  Default [DF_SoftUpTB_CreateDate]    Script Date: 10/21/2023 16:54:58 ******/
ALTER TABLE [dbo].[SoftUpTB] ADD  CONSTRAINT [DF_SoftUpTB_CreateDate]  DEFAULT (getdate()) FOR [CreateDate]
GO
/****** Object:  Default [DF_SoftUpLog_CreateDate]    Script Date: 10/21/2023 16:54:58 ******/
ALTER TABLE [dbo].[SoftUpLog] ADD  CONSTRAINT [DF_SoftUpLog_CreateDate]  DEFAULT (getdate()) FOR [CreateDate]
GO

注意事项:
请将数据库的配置文件存放在 源程序的执行目录的 config文件夹下。。因为配置文件地址获取的问题,只能获取到 源程序下的 config文件夹。/(‘@./config/update.conf’)

你可能感兴趣的:(c#)