コード例 #1
0
ファイル: AppMain.cs プロジェクト: thachgiasoft/shuijin
        private static void TestCfgWrite()
        {
            UpgradeCfg oCfg = new UpgradeCfg();

            oCfg.ServerUpgradePackageUrl = "http://vr.4008289828.com/Uploads/system_version";
            oCfg.ServerUpgradeConfigUrl  = "http://vr.4008289828.com/Uploads/system_version/release.txt";
            string json = JsonUtility.Encode(oCfg);

            File.WriteAllText(CfgPath, json);
        }
コード例 #2
0
ファイル: AppMain.cs プロジェクト: thachgiasoft/shuijin
        public static void Startup()
        {
            //TestRemoteWrite();
            //TestLocalWrite();
            //TestCfgWrite();

            // 获取本地版本号
            try
            {
                if (File.Exists(CfgPath) == false)
                {
                    Sb.Append("没有找到版本文件:" + VLocalPath);
                    MainWindow.TxtVersion.Content = "无法获取配置文件";
                }
                else
                {
                    string     cfgJson = File.ReadAllText(CfgPath);
                    UpgradeCfg oCfg    = JsonUtility.Decode <UpgradeCfg>(cfgJson);
                    ServerUpgradePackageUrl = oCfg.ServerUpgradePackageUrl;
                    ServerUpgradeConfigUrl  = oCfg.ServerUpgradeConfigUrl;
                }

                if (File.Exists(VLocalPath) == false)
                {
                    Sb.Append("没有找到版本文件:" + VLocalPath);
                    MainWindow.TxtVersion.Content = "无法获取软件信息";
                }
                else
                {
                    string localVersion = File.ReadAllText(VLocalPath);

                    if (string.IsNullOrEmpty(localVersion) == true)
                    {
                        Sb.Append("版本信息为空:" + VLocalPath);
                        MainWindow.TxtVersion.Content = "无法获取软件信息";
                    }
                    else
                    {
                        LocalVersionExt = JsonUtility.Decode <VersionExt>(localVersion);

                        MainWindow.TxtVersion.Content = LocalVersionExt.Release.Version.Replace(".zip", "");

                        LocalVersion = new Version(LocalVersionExt.Release.Version);
                    }
                }
            }
            catch (System.Exception e)
            {
                Sb.Append("出现异常:" + e.ToString());
                MainWindow.TxtVersion.Content = "无法获取软件信息";
            }

            if (LocalVersionExt != null)
            {
                string content = string.Empty;

                try
                {
                    HttpHelper oHeper = new HttpHelper();
                    content = oHeper.HttpGet(ServerUpgradeConfigUrl, string.Empty);
                }
                catch (Exception e)
                {
                    // 这里进行日志输出
                    Sb.Append(e.ToString());
                }

                if (string.IsNullOrEmpty(content) == true)
                {
                    MainWindow.TxtUpdateInfo.Content = "无法连接到服务器!";
                    string localVersion = LocalVersionExt.Release.Name.Replace(".zip", "");
                    Process(LocalPath + "/" + localVersion);
                }
                else
                {
                    // 解析服务器版本号,获取最后的版本
                    VersionInfos versionInfos = JsonUtility.Decode <VersionInfos>(content);

                    //Version oCompareRemoteVersion = new Version(LocalVersion.ToString());
                    //for (int i = 0; i < versionInfos.Release.Length; i++)
                    //{
                    //    VersionInfo oTmpRemoteVersionInfo= versionInfos.Release[i];
                    //    Version oTmpRemoteVersion = new Version(oTmpRemoteVersionInfo.Version);
                    //    if (oTmpRemoteVersion.Compare(oCompareRemoteVersion.ToString()) == 1)
                    //    {
                    //        oCompareRemoteVersion = oTmpRemoteVersion;
                    //    }
                    //}

                    VersionInfo remoteVersionInfo = versionInfos.Release[versionInfos.Release.Length - 1];
                    RemoteVersionExt = new VersionExt()
                    {
                        Release = remoteVersionInfo
                    };
                    try
                    {
                        Version localTMPV   = new Version(LocalVersionExt.Release.Version);
                        Version remoteTMPV  = new Version(RemoteVersionExt.Release.Version);
                        int     versionCode = localTMPV.Compare(remoteTMPV.ToString());
                        if (versionCode == -1)
                        {
                            // 输入版本大于当前版本
                            MainWindow.TxtNextVersion.Content = remoteTMPV.ToString().Replace(".zip", "");
                            string appUrl = ServerUpgradePackageUrl + "/" + Path.GetFileNameWithoutExtension(remoteVersionInfo.Name) + ".zip";
                            LocalZip = LocalPath + "/" + Path.GetFileNameWithoutExtension(remoteVersionInfo.Name) + ".zip";
                            ZCSharpLib.App.Make <HttpLoader>().AddLoad(appUrl, LocalZip, OnFinishedHandler, OnProgressHandler);
                        }
                        else
                        {
                            string localVersion = LocalVersionExt.Release.Name.Replace(".zip", "");
                            Process(LocalPath + "/" + localVersion);
                        }
                    }
                    catch (System.Exception e)
                    {
                        Sb.Append("\r\n" + e.ToString());
                    }
                }

                File.WriteAllText(UpgradeInfo, Sb.ToString());
            }
        }