Exemple #1
0
        private List <NeedOtaFile> CheckOtaFiles(List <OtaFile> listOtaFiles)
        {
            if (listOtaFiles == null)
            {
                return(null);
            }

            List <NeedOtaFile> needOtaFiles = new List <NeedOtaFile>();

            for (var i = 0; i < listOtaFiles.Count; i++)
            {
                OtaFile     otaFile     = listOtaFiles[i];
                NeedOtaFile needOtaFile = new NeedOtaFile();
                needOtaFile.fileName  = otaFile.FileName;
                needOtaFile.otaUrl    = otaFile.DownloadUrl;
                needOtaFile.localPath = otaFile.RelativePath.TrimStart('\\');
                needOtaFile.md5       = otaFile.FileMd5;
                if (!needOtaFile.CheckMd5())
                {   //需要更新
                    needOtaFile.index = needOtaFiles.Count;
                    needOtaFiles.Add(needOtaFile);
                }
            }

            return(needOtaFiles);
        }
Exemple #2
0
        // GET api/<controller>/5
        public string Get(string id)
        {
            try
            {
                string rootPath   = HostingEnvironment.MapPath("~");
                string updatePath = Path.Combine(rootPath, "Update", id);
                if (!Directory.Exists(updatePath))
                {
                    return("err_" + "请求的路径无效");
                }

                string[] ups    = Directory.GetDirectories(updatePath, "*", SearchOption.TopDirectoryOnly);
                string   newdir = ups.Max();
                if (string.IsNullOrWhiteSpace(newdir))
                {
                    return(null);
                }

                string upStr     = null;
                string cachePath = Path.Combine(newdir, "ota", "CacheUpdate");
                if (File.Exists(cachePath))
                {
                    upStr = File.ReadAllText(cachePath);
                }
                else
                {
                    OtaInfo otaInfo = new OtaInfo()
                    {
                        AppID = id
                    };
                    otaInfo.AppName = File.ReadAllText(Path.Combine(updatePath, "Name.txt"));
                    otaInfo.AppGUID = File.ReadAllText(Path.Combine(updatePath, "GUID.txt"));

                    DateTime upTime = DateTime.ParseExact(Path.GetFileNameWithoutExtension(newdir), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                    otaInfo.AppVerTime = upTime;
                    string[] lines      = File.ReadAllLines(Path.Combine(newdir, "Version.txt"));
                    string   newVersion = lines[0].Substring(3);
                    otaInfo.AppVersion = newVersion;
                    otaInfo.AppVerText = string.Join("\n", lines);
                    otaInfo.MainFile   = File.ReadAllText(Path.Combine(newdir, "MainFile.txt"));
                    otaInfo.SetupUrl   = LocalPath2WebPath(Path.Combine(newdir, "Setup.exe"));
                    otaInfo.OtaFiles   = new List <OtaFile>();

                    List <string> otas = Directory.GetFiles(Path.Combine(newdir, "ota"), "*", SearchOption.AllDirectories).ToList();
                    if (File.Exists(Path.Combine(rootPath, "Update", "Common", id)))
                    {
                        string[] commFileNames = JsonConvert.DeserializeObject <string[]>(File.ReadAllText(Path.Combine(rootPath, "Update", "Common", id), Encoding.UTF8));
                        for (int i = 0; i < commFileNames.Length; i++)
                        {
                            otas.Add(Path.Combine(rootPath, "Update", "Common", "Files", commFileNames[i]));
                        }
                    }

                    for (int i = 0; i < otas.Count; i++)
                    {
                        string  otaFilePath = otas[i];
                        OtaFile file        = new OtaFile();
                        file.FileName    = Path.GetFileName(otaFilePath);
                        file.FileMd5     = GetMd5ByFilePath2(otaFilePath);
                        file.DownloadUrl = LocalPath2WebPath(otaFilePath);
                        string tmpPath = Path.Combine(newdir, "ota");
                        if (otaFilePath.StartsWith(tmpPath))
                        {
                            file.RelativePath = otaFilePath.Substring(tmpPath.Length);
                        }
                        else
                        {
                            tmpPath = Path.Combine(rootPath, "Update", "Common", "Files");
                            if (otaFilePath.StartsWith(tmpPath))
                            {
                                file.RelativePath = otaFilePath.Substring(tmpPath.Length);
                            }
                        }
                        otaInfo.OtaFiles.Add(file);
                    }

                    upStr = JsonConvert.SerializeObject(otaInfo);
                    upStr = upStr.ToBase64String();
                    File.WriteAllText(cachePath, upStr);
                }
                return(upStr);
            }
            catch (Exception e)
            {
                return("err_" + e.Message);
            }
        }