Esempio n. 1
0
        public static ResourceType GetType(string path)
        {
            try
            {
                if (Directory.Exists(path))
                {
                    return(ResourceType.Folder);
                }
                if (!File.Exists(path))
                {
                    return(ResourceType.MissingFile);
                }

                using (var r = new BinaryReader(File.Open(path, FileMode.Open,
                                                          FileAccess.Read, FileShare.ReadWrite)))
                {
                    if (!ResourceSignature.Read(r))
                    {
                        return(ResourceType.NotResource);
                    }
                    var type    = StringToType(r.ReadString());
                    var version = r.ReadString();
                    if (CurrentVersion(type) != version)
                    {
                        return(ResourceType.Outdated);
                    }
                    return(type);
                }
            }
            catch
            {
                return(ResourceType.NotResource);
            }
        }
Esempio n. 2
0
 public void Save(string path)
 {
     using (var w = new BinaryWriter(File.Create(path)))
     {
         ResourceSignature.Write(w);
         w.Write(TypeToString(Type));
         w.Write(Version);
         w.Write(ResourceSignature.TimeStamp);
         ID.Write(w);
         WriteData(w);
     }
 }
Esempio n. 3
0
        public void Open(string path)
        {
            using (var r = new BinaryReader(File.OpenRead(path)))
            {
                if (!ResourceSignature.Read(r))
                {
                    throw new Exception(
                              "Invalid resource [" + path + "] signature.");
                }

                Type      = StringToType(r.ReadString());
                Version   = r.ReadString();
                TimeStamp = r.ReadString();
                ID        = new ResourceID(r);
                ReadData(r);
            }
        }
Esempio n. 4
0
        private static void Description0000to0001(string path)
        {
            string name = null;

            using (var reader = new BinaryReader(File.OpenRead(path)))
            {
                if (!Description.ReadSignature(reader))
                {
                    throw new Exception("Invalid description base file format.");
                }
                reader.ReadString(); // do not care about current version
                name = reader.ReadString();
            }

            var resources_path = Path.GetFullPath(path);

            resources_path = Path.Combine(Path.GetDirectoryName(resources_path), "Resources");
            var files = Directory.GetFiles(resources_path, "*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                if (Resource.GetType(file).ValidBinary())
                {
                    var bytes = File.ReadAllBytes(file);
                    using (var reader = new BinaryReader(new MemoryStream(bytes)))
                        using (var writer = new BinaryWriter(File.OpenWrite(file)))
                        {
                            ResourceSignature.Read(reader);
                            ResourceSignature.Write(writer);
                            writer.Write(reader.ReadString());
                            writer.Write(reader.ReadString());
                            writer.Write(reader.ReadString());
                            new ResourceID().Write(writer);
                            writer.Write(reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)));
                        }
                }
            }

            using (var writer = new BinaryWriter(File.OpenWrite(path)))
            {
                Description.WriteSignature(writer);
                writer.Write("0.0.0.1");
                writer.Write(name);
            }
        }
Esempio n. 5
0
        public static ResourceID GetID(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            using (var r = new BinaryReader(File.OpenRead(path)))
            {
                if (!ResourceSignature.Read(r))
                {
                    return(null);
                }
                var type      = r.ReadString();
                var version   = r.ReadString();
                var timestamp = r.ReadString();
                return(null);
            }
        }