Beispiel #1
0
        private List <FileVersionInfo> GetLocalFileVersionInfo()
        {
            var filelist = new List <string> {
                "CozyLauncher.exe",
                "CozyLauncher.Core.dll",
                "CozyLauncher.Infrastructure.dll",
                "CozyLauncher.PluginBase.dll",

                "NHotkey.dll",
                "NHotkey.Wpf.dll",
                "Newtonsoft.Json.dll",
                "YAMP.dll",
                "System.Windows.Interactivity.dll",

                "CozyLauncher.Plugin.Core.dll",

                "CozyLauncher.Plugin.Program.dll",
                "CozyLauncher.Plugin.Dirctory.dll",
                "CozyLauncher.Plugin.ManualRun.dll",
                "CozyLauncher.Plugin.WebSearch.dll",
                "CozyLauncher.Plugin.Ip.dll",
                "CozyLauncher.Plugin.Sys.dll",
                "CozyLauncher.Plugin.Calculator.dll",

                "CozyLauncher.Plugin.MouseClick.dll",
            };

            return(filelist.Select(x => new FileVersionInfo
            {
                Name = x,
                Md5 = FileMd5.GetMD5HashFromFile((PathTransform.LocalFullPath(Path.Combine("..\\", x)))),
            }).ToList());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            List <FileVersionInfo> filelist = new List <FileVersionInfo>();

            foreach (var file in Directory.GetFiles(args[0]))
            {
                if (Path.GetExtension(file) == ".exe" || Path.GetExtension(file) == ".dll")
                {
                    filelist.Add(new FileVersionInfo
                    {
                        Name = Path.GetFileName(file),
                        Md5  = FileMd5.GetMD5HashFromFile(PathTransform.LocalFullPath(file)),
                    });
                }
            }

            // to json
            var filename = (args.Length < 2 || string.IsNullOrEmpty(args[1])) ? "./publish.json" : args[1];

            using (var fs = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite))
            {
                using (var sr = new StreamWriter(fs))
                {
                    sr.Write(JsonConvert.SerializeObject(filelist));
                }
            }
        }
Beispiel #3
0
        public async Task <ApiResponse <string> > CreateFileMd5ByDataKey(string key)
        {
            var path = _uploadSetting.GetStoragePath(key);

            if (!File.Exists(path))
            {
                return(ApiResponse.NotFound <string>("file not exists"));
            }
            var md5 = GetMD5HashFromFile(path);

            if (string.IsNullOrEmpty(md5))
            {
                return(ApiResponse.NotFound <string>("file md5 failed"));
            }
            using (var scope = GlobalServices.Container.BeginLifetimeScope())
            {
                var repository = scope.Resolve <ICloudSpeedRepository>();
                var entity     = new FileMd5()
                {
                    Id = md5, DataKey = key
                };
                await repository.CreateFileMd5(entity);

                await repository.Commit();

                return(ApiResponse.Ok <string>(entity.Id));
            }
        }
        private void button1_Update_Click(object sender, EventArgs e)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            WebClient client = new WebClient();

            try
            {
                // 下载更新文件
                client.DownloadFile(FileUrl, temp_filename);

                // 判断下载的文件是否存在
                if (!File.Exists(temp_filename))
                {
                    throw new Exception("下载更新文件失败");
                }

                // 判断下载的文件MD5是否和Xml文件中的一致
                if (!FileMd5.ToLower().Equals(GetMd5(temp_filename).ToLower()))
                {
                    throw new Exception("下载的文件MD5不一致");
                }

                // 写脚本
                string bat =
                    "@ping -n 2 127.1 > nul\r\n"                                       // 延时2秒等待软件退出
                    + "del /f \"" + downloadPath + "\"\r\n"                            // 删除原文件
                    + "move /y \"" + temp_filename + "\" \"" + downloadPath + "\"\r\n" // 重命名文件
                    + "start \"自动进入钉钉直播间\" " + downloadPath + "\"\r\n"                 // 打开新文件
                    + "del /f %0\r\n";
                //+ "pause";
                File.WriteAllText(batPath, bat, Encoding.GetEncoding("GB2312"));   // 写入bat文件
                FileInfo fi = new FileInfo(batPath);
                if (fi.Exists)
                {
                    fi.Attributes = FileAttributes.Hidden;                        // 设置属性为隐藏
                }
                // 运行脚本
                Process pro = new Process();
                pro.StartInfo.WorkingDirectory = Application.StartupPath;
                pro.StartInfo.FileName         = batPath;
                pro.StartInfo.WindowStyle      = ProcessWindowStyle.Normal;
                //pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                pro.Start();

                // 杀死当前进程
                Process.GetCurrentProcess().Kill();
            }
            catch (Exception ex)
            {
                Clipboard.SetText(FileUrl); // 将下载链接复制到剪贴板
                MessageBox.Show("更新失败,已将下载链接复制到剪切板。\n原因:" + ex.Message, "自动进入钉钉直播间_更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                button2_CancelUpdate_Click(null, null);
            }
            finally
            {
                client.Dispose();
            }
        }
Beispiel #5
0
        public async Task CreateFileMd5(string id, string dataKey)
        {
            using (var scope = GlobalServices.Container.BeginLifetimeScope())
            {
                var repository = scope.Resolve <ICloudSpeedRepository>();
                var entity     = new FileMd5()
                {
                    Id = id, DataKey = dataKey
                };
                await repository.CreateFileMd5(entity);

                await repository.Commit();
            }
        }
Beispiel #6
0
        // 获取更新
        public static bool GetUpdate()
        {
            string currentVersion = Application.ProductVersion;                                           // 当前程序版本
            string xmlUrl         = "https://gitee.com/fuhohua/Web/raw/master/DD/Update.xml";             // XML文件下载地址
            string xmlPath        = Environment.GetEnvironmentVariable("TEMP") + "\\自动进入钉钉直播间Update.xml"; // XML本地路径
            string downFilePath   = Process.GetCurrentProcess().MainModule.FileName;                      // 当前程序名称
            string temp_File      = downFilePath + ".tmp";                                                // 临时文件
            string batPath        = Application.StartupPath + "\\自动进入钉钉直播间ren.bat";                       // 脚本文件

            // 删除上次残余文件
            if (File.Exists(temp_File))
            {
                File.Delete(temp_File);
            }
            if (File.Exists(batPath))
            {
                File.Delete(batPath);
            }
            if (File.Exists(xmlPath))
            {
                File.Delete(xmlPath);
            }


            // 下载Xml文件
            System.Net.WebClient client = new System.Net.WebClient();
            client.DownloadFile(xmlUrl, xmlPath);

            // 判断Xml文件是否存在
            if (!File.Exists(xmlPath))
            {
                throw new Exception("下载XML文件失败!");
            }

            // 加载Xml文件
            XmlDocument xml = new XmlDocument();

            xml.Load(xmlPath);
            // 得到根节点
            XmlNode     node = xml.SelectSingleNode("AutoUpdate");
            XmlNodeList list = node.ChildNodes;

            foreach (XmlNode xn in list)
            {
                // 将节点转为元素
                XmlElement element = (XmlElement)xn;
                // 得到Version属性的值
                UpdateVersion = element.GetAttribute("Version");
                // 得到Update节点的所有子节点
                XmlNodeList nodeList = element.ChildNodes;
                FileName   = nodeList.Item(0).InnerText;
                FileMd5    = nodeList.Item(1).InnerText;
                FileUrl    = nodeList.Item(2).InnerText;
                UpdateCont = nodeList.Item(3).InnerText;
            }
            // 删除Xml文件
            if (File.Exists(xmlPath))
            {
                File.Delete(xmlPath);
            }


            // 比较版本号,如果当前版本小于升级版本
            if (string.Compare(currentVersion, UpdateVersion) < 0)
            {
                DialogResult result = MessageBox.Show("当前程序出新版啦!是否更新呢?"
                                                      + "\n当前版本:" + currentVersion
                                                      + "\n最新版本:" + UpdateVersion
                                                      + "\n更新内容:" + UpdateCont,
                                                      "发现新版本", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.No)
                {
                    return(false);
                }

                MessageBox.Show("正在下载更新,下载完后会自动打开~", "正在下载更新", MessageBoxButtons.OK, MessageBoxIcon.Information);

                try
                {
                    // 下载更新文件
                    client.DownloadFile(FileUrl, temp_File);
                    // 判断下载的文件是否存在
                    if (!File.Exists(temp_File))
                    {
                        throw new Exception("下载更新文件失败!");
                    }


                    // 判断下载的文件MD5是否和Xml文件中的一致
                    if (!FileMd5.ToLower().Equals(GetMd5(temp_File).ToLower()))
                    {
                        throw new Exception("下载的文件MD5不一致!");
                    }


                    // 写脚本
                    string bat = "@ping -n 1 127.1 >nul"                           // 延时1秒等待软件退出
                                 + "\r\ndel " + downFilePath                       // 删除原文件
                                 + "\r\nmove /y " + temp_File + " " + downFilePath // 重命名文件
                                 + "\r\n" + "start " + downFilePath                // 打开新文件
                                 + "\r\ndel %0";
                    //+ "\r\npause";
                    File.WriteAllText(batPath, bat, Encoding.GetEncoding("GB2312"));  // 写入bat文件

                    // 运行脚本
                    Process pro = new Process();
                    pro.StartInfo.WorkingDirectory = Application.StartupPath;
                    pro.StartInfo.FileName         = batPath;
                    //pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    pro.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                    pro.Start();

                    // 杀死当前进程
                    Process.GetCurrentProcess().Kill();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #7
0
 public async Task CreateFileMd5(FileMd5 entity)
 {
     await DbContext.FileMd5s.AddAsync(entity);
 }