HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-09-23 c0ce2f57a4f836ebeb9e7b8b4b5a4407fd78dc86
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs
@@ -445,7 +445,11 @@
            //获取需要下载的固件数据
            var listVersion = GetNeedToDownLoadVersionData(listTempDevice, listTempGateway);
            if (listVersion.Count == 0)
            //获取需要下载的空调模块
            var listAcOta = new List<OTADevice>();
            var listAcUpdate = GetNeedDownLoadAirConditionerModule(listTempDevice, ref listAcOta);
            if (listVersion.Count == 0 && listAcUpdate.Count == 0)
            {
                return 0;
            }
@@ -468,6 +472,8 @@
            //固件存储路径
            string firmwareDir = DirNameResourse.FirmwareUpdateDirectory;
            int nowCount = 0;
            int macCount = listVersion.Count + listAcUpdate.Count;
            foreach (var versionData in listVersion)
            {
                nowCount++;
@@ -476,6 +482,8 @@
                if (result == -1)
                {
                    ProgressFormBar.Current.Close();
                    //保存列表名字
                    HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName);
                    return -1;
                }
                //获取当前这个版本的固件信息
@@ -483,15 +491,17 @@
                if (versionFirmware == null)
                {
                    //云端没有这个版本  进度值
                    ProgressFormBar.Current.SetValue(nowCount, listVersion.Count);
                    ProgressFormBar.Current.SetValue(nowCount, macCount);
                    continue;
                }
                //去下载这个固件
                var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = versionFirmware.DistributedMark };
                var byteData = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, null, true);
                var byteData = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, new List<string> { "NotCheck" }, true);
                if (byteData == null)
                {
                    ProgressFormBar.Current.Close();
                    //保存列表名字
                    HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName);
                    return -1;
                }
                //保存固件
@@ -500,8 +510,29 @@
                dicFirmwareName[saveFile] = versionFirmware.Name;
                //进度值
                ProgressFormBar.Current.SetValue(nowCount, listVersion.Count);
                ProgressFormBar.Current.SetValue(nowCount, macCount);
            }
            for (int i = 0; i < listAcUpdate.Count; i++)
            {
                //下载空调模块
                var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = listAcUpdate[i].DistributedMark };
                var deviceFirmwareByte = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, new List<string> { "NotCheck" }, true);
                if (deviceFirmwareByte == null)
                {
                    ProgressFormBar.Current.Close();
                    //保存列表名字
                    HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName);
                    return -1;
                }
                //保存固件
                string fileName = "AC_" + listAcOta[i].HwVersion + "_" + listAcOta[i].ImgTypeId + "_" + listAcUpdate[i].Name;
                var saveFile = System.IO.Path.Combine(firmwareDir, fileName);
                HdlFileLogic.Current.SaveByteToFile(saveFile, deviceFirmwareByte);
                //进度值
                ProgressFormBar.Current.SetValue(nowCount, macCount);
            }
            //保存列表名字
            HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName);
            ProgressFormBar.Current.Close();
@@ -601,6 +632,39 @@
        }
        /// <summary>
        /// 获取需要下载的空调模块
        /// </summary>
        /// <param name="listDevice">设备列表</param>
        /// <param name="listTaget">与返回值对应的东西</param>
        private static List<FirmwareVersionInfo> GetNeedDownLoadAirConditionerModule(List<OTADevice> listDevice, ref List<OTADevice> listTaget)
        {
            var listUpdate = new List<FirmwareVersionInfo>();
            //固件存储路径
            string firmwareDir = DirNameResourse.FirmwareUpdateDirectory;
            foreach (var otaDevice in listDevice)
            {
                var myType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice> { otaDevice });
                if (myType.ConcreteType != Common.DeviceConcreteType.AirConditioner_ZbGateway)
                {
                    //只处理中央空调
                    continue;
                }
                var list = GetFirmwareVersionListInfo(FirmwareLevelType.A设备, otaDevice.HwVersion.ToString(), otaDevice.ImgTypeId.ToString());
                foreach (var data in list)
                {
                    if (data.Name.EndsWith(".bin") == true && System.IO.File.Exists(firmwareDir) == false)
                    {
                        //只要.bin文件
                        listUpdate.Add(data);
                        listTaget.Add(otaDevice);
                    }
                }
            }
            return listUpdate;
        }
        /// <summary>
        /// 模板设备的版本信息
        /// </summary>
        private class TemplateDeviceVersion