コード例 #1
0
ファイル: IndexFile.cs プロジェクト: spritefun/gta2net
        public static void Save()
        {
            var versionAttributes = NamedVersionAttribute.GetTypesWithVersionAttribute(Assembly.GetExecutingAssembly());

            using (var writer = new BinaryWriter(new FileStream(Globals.IndexFile, FileMode.CreateNew, FileAccess.ReadWrite)))
            {
                writer.Write("GTA2.NET");
                writer.Write(IndexFileVersion); //Index-File version
                writer.Write(versionAttributes.Count);
                foreach (var versionAttribute in versionAttributes)
                {
                    writer.Write(versionAttribute.Key);
                    writer.Write(versionAttribute.Value.ToString());
                }
            }
        }
コード例 #2
0
ファイル: IndexFile.cs プロジェクト: spritefun/gta2net
 //true = all files are ok, no need to update
 public static bool Vertify()
 {
     try
     {
         using (var reader = new BinaryReader(new FileStream(Globals.IndexFile, FileMode.Open, FileAccess.Read)))
         {
             reader.ReadString(); //GTA2.NET
             var fileVersion  = new Version(reader.ReadString());
             var localVersion = new Version(IndexFileVersion);
             if (fileVersion < localVersion)
             {
                 return(false);
             }
             var localVersionAttributes = NamedVersionAttribute.GetTypesWithVersionAttribute(Assembly.GetExecutingAssembly());
             var fileVersionAttributes  = new Dictionary <string, Version>();
             var count = reader.ReadInt32();
             for (var i = 0; i < count; i++)
             {
                 fileVersionAttributes.Add(reader.ReadString(), new Version(reader.ReadString()));
             }
             foreach (var localVersionAttribute in localVersionAttributes)
             {
                 Version version;
                 if (!fileVersionAttributes.TryGetValue(localVersionAttribute.Key, out version))
                 {
                     return(false);
                 }
                 if (version < localVersionAttribute.Value)
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.Message);
         return(false);
     }
 }