private static int CompareComponents(UpdateComponentInfo a, UpdateComponentInfo b) { if(a.Name == b.Name) return 0; if(a.Name == PwDefs.ShortProductName) return -1; if(b.Name == PwDefs.ShortProductName) return 1; return a.Name.CompareTo(b.Name); }
private static void AddComponent(List<UpdateComponentInfo> l, UpdateComponentInfo c) { if((l == null) || (c == null)) { Debug.Assert(false); return; } for(int i = l.Count - 1; i >= 0; --i) { if(l[i].Name.Equals(c.Name, StrUtil.CaseIgnoreCmp)) l.RemoveAt(i); } l.Add(c); }
private static List <UpdateComponentInfo> LoadInfoFilePriv(byte[] pbData, IOConnectionInfo iocSource) { if ((pbData == null) || (pbData.Length == 0)) { return(null); } string strData = StrUtil.Utf8.GetString(pbData); strData = StrUtil.NormalizeNewLines(strData, false); string[] vLines = strData.Split('\n'); List <UpdateComponentInfo> l = new List <UpdateComponentInfo>(); bool bHeader = true, bFooterFound = false; char chSep = ':'; // Modified by header for (int i = 0; i < vLines.Length; ++i) { string str = vLines[i].Trim(); if (str.Length == 0) { continue; } if (bHeader) { chSep = str[0]; bHeader = false; } else if (str[0] == chSep) { bFooterFound = true; break; } else // Component info { string[] vInfo = str.Split(new char[] { chSep }); if (vInfo.Length >= 2) { UpdateComponentInfo c = new UpdateComponentInfo( vInfo[0].Trim(), 0, iocSource.Path, string.Empty); c.VerAvailable = StrUtil.ParseVersion(vInfo[1]); AddComponent(l, c); } } } return(bFooterFound ? l : null); }
private static bool SetComponentAvail(UpdateComponentInfo uc, List <UpdateComponentInfo> lAvail) { if (uc == null) { Debug.Assert(false); return(false); } if (lAvail == null) { return(false); // No assert } if ((uc.Name == CompMain) && WinUtil.IsAppX) { // The user's AppX may be old; do not claim it's up-to-date // uc.VerAvailable = uc.VerInstalled; // uc.Status = UpdateComponentStatus.UpToDate; uc.Status = UpdateComponentStatus.Unknown; return(true); } foreach (UpdateComponentInfo ucAvail in lAvail) { if (ucAvail.Name.Equals(uc.Name, StrUtil.CaseIgnoreCmp)) { uc.VerAvailable = ucAvail.VerAvailable; if (uc.VerInstalled == uc.VerAvailable) { uc.Status = UpdateComponentStatus.UpToDate; } else if (uc.VerInstalled < uc.VerAvailable) { uc.Status = UpdateComponentStatus.NewVerAvailable; } else { uc.Status = UpdateComponentStatus.PreRelease; } return(true); } } return(false); }
private static int CompareComponents(UpdateComponentInfo a, UpdateComponentInfo b) { if (a.Name == b.Name) { return(0); } if (a.Name == PwDefs.ShortProductName) { return(-1); } if (b.Name == PwDefs.ShortProductName) { return(1); } return(a.Name.CompareTo(b.Name)); }
private static int CompareComponents(UpdateComponentInfo a, UpdateComponentInfo b) { if (a.Name == b.Name) { return(0); } if (a.Name == CompMain) { return(-1); } if (b.Name == CompMain) { return(1); } return(a.Name.CompareTo(b.Name)); }
private static bool SetComponentAvail(UpdateComponentInfo uc, List <UpdateComponentInfo> lAvail) { if (uc == null) { Debug.Assert(false); return(false); } if (lAvail == null) { return(false); // No assert } foreach (UpdateComponentInfo ucAvail in lAvail) { if (ucAvail.Name.Equals(uc.Name, StrUtil.CaseIgnoreCmp)) { uc.VerAvailable = ucAvail.VerAvailable; if (uc.VerInstalled == uc.VerAvailable) { uc.Status = UpdateComponentStatus.UpToDate; } else if (uc.VerInstalled < uc.VerAvailable) { uc.Status = UpdateComponentStatus.NewVerAvailable; } else { uc.Status = UpdateComponentStatus.PreRelease; } return(true); } } return(false); }
private static bool SetComponentAvail(UpdateComponentInfo uc, List<UpdateComponentInfo> lAvail) { if(uc == null) { Debug.Assert(false); return false; } if(lAvail == null) return false; // No assert foreach(UpdateComponentInfo ucAvail in lAvail) { if(ucAvail.Name.Equals(uc.Name, StrUtil.CaseIgnoreCmp)) { uc.VerAvailable = ucAvail.VerAvailable; if(uc.VerInstalled == uc.VerAvailable) uc.Status = UpdateComponentStatus.UpToDate; else if(uc.VerInstalled < uc.VerAvailable) uc.Status = UpdateComponentStatus.NewVerAvailable; else uc.Status = UpdateComponentStatus.PreRelease; return true; } } return false; }
private static List<UpdateComponentInfo> LoadInfoFilePriv(byte[] pbData, IOConnectionInfo iocSource) { if((pbData == null) || (pbData.Length == 0)) return null; int iOffset = 0; StrEncodingInfo sei = StrUtil.GetEncoding(StrEncodingType.Utf8); byte[] pbBom = sei.StartSignature; if((pbData.Length >= pbBom.Length) && MemUtil.ArraysEqual(pbBom, MemUtil.Mid(pbData, 0, pbBom.Length))) iOffset += pbBom.Length; string strData = sei.Encoding.GetString(pbData, iOffset, pbData.Length - iOffset); strData = StrUtil.NormalizeNewLines(strData, false); string[] vLines = strData.Split('\n'); List<UpdateComponentInfo> l = new List<UpdateComponentInfo>(); bool bHeader = true, bFooterFound = false; char chSep = ':'; // Modified by header for(int i = 0; i < vLines.Length; ++i) { string str = vLines[i].Trim(); if(str.Length == 0) continue; if(bHeader) { chSep = str[0]; bHeader = false; } else if(str[0] == chSep) { bFooterFound = true; break; } else // Component info { string[] vInfo = str.Split(new char[] { chSep }); if(vInfo.Length >= 2) { UpdateComponentInfo c = new UpdateComponentInfo( vInfo[0].Trim(), 0, iocSource.Path, string.Empty); c.VerAvailable = StrUtil.ParseVersion(vInfo[1]); AddComponent(l, c); } } } return (bFooterFound ? l : null); }
private static int CompareComponents(UpdateComponentInfo a, UpdateComponentInfo b) { if(a.Name == b.Name) return 0; if(a.Name == PwDefs.ShortProductName) return -1; if(b.Name == PwDefs.ShortProductName) return 1; return a.Name.CompareTo(b.Name); }
private static void AddComponent(List<UpdateComponentInfo> l, UpdateComponentInfo c) { if((l == null) || (c == null)) { Debug.Assert(false); return; } for(int i = l.Count - 1; i >= 0; --i) { if(l[i].Name.Equals(c.Name, StrUtil.CaseIgnoreCmp)) l.RemoveAt(i); } l.Add(c); }
private static List<UpdateComponentInfo> LoadInfoFilePriv(byte[] pbData, IOConnectionInfo iocSource) { if((pbData == null) || (pbData.Length == 0)) return null; string strData = StrUtil.Utf8.GetString(pbData); strData = StrUtil.NormalizeNewLines(strData, false); string[] vLines = strData.Split('\n'); List<UpdateComponentInfo> l = new List<UpdateComponentInfo>(); bool bHeader = true, bFooterFound = false; char chSep = ':'; // Modified by header for(int i = 0; i < vLines.Length; ++i) { string str = vLines[i].Trim(); if(str.Length == 0) continue; if(bHeader) { chSep = str[0]; bHeader = false; } else if(str[0] == chSep) { bFooterFound = true; break; } else // Component info { string[] vInfo = str.Split(new char[] { chSep }); if(vInfo.Length >= 2) { UpdateComponentInfo c = new UpdateComponentInfo( vInfo[0].Trim(), 0, iocSource.Path, string.Empty); c.VerAvailable = StrUtil.ParseVersion(vInfo[1]); AddComponent(l, c); } } } return (bFooterFound ? l : null); }
private static List <UpdateComponentInfo> LoadInfoFilePriv(byte[] pbData, IOConnectionInfo iocSource) { if ((pbData == null) || (pbData.Length == 0)) { return(null); } int iOffset = 0; StrEncodingInfo sei = StrUtil.GetEncoding(StrEncodingType.Utf8); byte[] pbBom = sei.StartSignature; if ((pbData.Length >= pbBom.Length) && MemUtil.ArraysEqual(pbBom, MemUtil.Mid(pbData, 0, pbBom.Length))) { iOffset += pbBom.Length; } string strData = sei.Encoding.GetString(pbData, iOffset, pbData.Length - iOffset); strData = StrUtil.NormalizeNewLines(strData, false); string[] vLines = strData.Split('\n'); string strSigKey; g_dFileSigKeys.TryGetValue(iocSource.Path.ToLowerInvariant(), out strSigKey); string strLdSig = null; StringBuilder sbToVerify = ((strSigKey != null) ? new StringBuilder() : null); List <UpdateComponentInfo> l = new List <UpdateComponentInfo>(); bool bHeader = true, bFooterFound = false; char chSep = ':'; // Modified by header for (int i = 0; i < vLines.Length; ++i) { string str = vLines[i].Trim(); if (str.Length == 0) { continue; } if (bHeader) { chSep = str[0]; bHeader = false; string[] vHdr = str.Split(chSep); if (vHdr.Length >= 2) { strLdSig = vHdr[1]; } } else if (str[0] == chSep) { bFooterFound = true; break; } else // Component info { if (sbToVerify != null) { sbToVerify.Append(str); sbToVerify.Append('\n'); } string[] vInfo = str.Split(chSep); if (vInfo.Length >= 2) { UpdateComponentInfo c = new UpdateComponentInfo( vInfo[0].Trim(), 0, iocSource.Path, string.Empty); c.VerAvailable = StrUtil.ParseVersion(vInfo[1]); AddComponent(l, c); } } } if (!bFooterFound) { Debug.Assert(false); return(null); } if (sbToVerify != null) { if (!VerifySignature(sbToVerify.ToString(), strLdSig, strSigKey)) { return(null); } } return(l); }
private static List<UpdateComponentInfo> LoadInfoFilePriv(byte[] pbData, IOConnectionInfo iocSource) { if((pbData == null) || (pbData.Length == 0)) return null; int iOffset = 0; StrEncodingInfo sei = StrUtil.GetEncoding(StrEncodingType.Utf8); byte[] pbBom = sei.StartSignature; if((pbData.Length >= pbBom.Length) && MemUtil.ArraysEqual(pbBom, MemUtil.Mid(pbData, 0, pbBom.Length))) iOffset += pbBom.Length; string strData = sei.Encoding.GetString(pbData, iOffset, pbData.Length - iOffset); strData = StrUtil.NormalizeNewLines(strData, false); string[] vLines = strData.Split('\n'); string strSigKey; g_dFileSigKeys.TryGetValue(iocSource.Path.ToLowerInvariant(), out strSigKey); string strLdSig = null; StringBuilder sbToVerify = ((strSigKey != null) ? new StringBuilder() : null); List<UpdateComponentInfo> l = new List<UpdateComponentInfo>(); bool bHeader = true, bFooterFound = false; char chSep = ':'; // Modified by header for(int i = 0; i < vLines.Length; ++i) { string str = vLines[i].Trim(); if(str.Length == 0) continue; if(bHeader) { chSep = str[0]; bHeader = false; string[] vHdr = str.Split(chSep); if(vHdr.Length >= 2) strLdSig = vHdr[1]; } else if(str[0] == chSep) { bFooterFound = true; break; } else // Component info { if(sbToVerify != null) { sbToVerify.Append(str); sbToVerify.Append('\n'); } string[] vInfo = str.Split(chSep); if(vInfo.Length >= 2) { UpdateComponentInfo c = new UpdateComponentInfo( vInfo[0].Trim(), 0, iocSource.Path, string.Empty); c.VerAvailable = StrUtil.ParseVersion(vInfo[1]); AddComponent(l, c); } } } if(!bFooterFound) { Debug.Assert(false); return null; } if(sbToVerify != null) { if(!VerifySignature(sbToVerify.ToString(), strLdSig, strSigKey)) return null; } return l; }