public void FillTo(ResourceInfo target) {
     target.Author = Author;
     target.ArchiveName = ArchiveName;
     target.Name = Name;
     target.Dependencies = Dependencies;
     target.Description = Description;
     target.Game = Game;
     target.ShortGame = ShortGame;
     target.ShortName = ShortName;
     target.PrimaryModVersion = PrimaryModVersion;
     target.CheckSum = CheckSum;
     target.ModType = ModType;
     target.Mutator = Mutator;
     target.ArchivePath = ArchivePath;
 }
        public ArchiveCache(string unitsyncWritableFolder) {
            Archives = new List<ResourceInfo>();

            var fi = GetCacheFile(unitsyncWritableFolder);
            if (fi != null)
            {
                var lua = new Lua();
                var luaEnv = lua.CreateEnvironment();
                using (var file = fi.OpenText())
                {
                    dynamic result = luaEnv.DoChunk(file, "dummy.lua");
                    foreach (var archive in result.archives)
                    {
                        var v = archive.Value;

                        if (v.archivedata != null)
                        {

                            var newEntry = new ResourceInfo()
                            {
                                ArchiveName = v.name,
                                ArchivePath = v.path,
                                Name = v.archivedata.name,
                                Author = v.archivedata.author,
                                Description = v.archivedata.description,
                                Mutator = v.mutator,
                                ShortGame = v.shortgame,
                                Game = v.game,
                                ShortName = v.shortname,
                                PrimaryModVersion = v.version,
                            };
                            if (v.archivedata.modtype != null) newEntry.ModType = v.archivedata.modtype;
                            if (v.checksum != null)
                            {
                                uint temp;
                                if (uint.TryParse(v.checksum, out temp)) newEntry.CheckSum = temp;
                            }
                            if (v.archivedata.depend != null) foreach (var dep in v.archivedata.depend) newEntry.Dependencies.Add(dep.Value);

                            Archives.Add(newEntry);
                        }
                    }
                }
            }
        }
 public static byte[] SerializeAndCompressMetaData(ResourceInfo info)
 {
     var serializedStream = new MemoryStream();
     new XmlSerializer(info.GetType()).Serialize(serializedStream, info);
     serializedStream.Position = 0;
     return serializedStream.ToArray().Compress();
 }
Esempio n. 4
0
        private static void Register(UnitSync unitsync, ResourceInfo resource)
        {
            Trace.TraceInformation("UnitSyncer: registering {0}", resource.Name);
            try
            {
                var info = unitsync.GetResourceFromFileName(resource.ArchivePath);

                if (info != null)
                {
                    var serializedData = MetaDataCache.SerializeAndCompressMetaData(info);

                    var map = info as Map;
                    var creator = new TorrentCreator();
                    creator.Path = resource.ArchivePath;
                    var ms = new MemoryStream();
                    creator.Create(ms);

                    byte[] minimap = null;
                    byte[] metalMap = null;
                    byte[] heightMap = null;
                    if (map != null)
                    {
                        minimap = map.Minimap.ToBytes(ImageSize);
                        metalMap = map.Metalmap.ToBytes(ImageSize);
                        heightMap = map.Heightmap.ToBytes(ImageSize);
                    }

                    var hash = Hash.HashBytes(File.ReadAllBytes(resource.ArchivePath));
                    var length = new FileInfo(resource.ArchivePath).Length;

                    Trace.TraceInformation("UnitSyncer: uploading {0} to server", info.Name);

                    ReturnValue e;
                    try
                    {
                        var service = GlobalConst.GetContentService();
                        e = service.RegisterResource(PlasmaServiceVersion,
                            null,
                            hash.ToString(),
                            (int)length,
                            info.ResourceType,
                            resource.ArchiveName,
                            info.Name,
                            serializedData,
                            info.Dependencies,
                            minimap,
                            metalMap,
                            heightMap,
                            ms.ToArray());
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("UnitSyncer: Error uploading data to server: {0}", ex);
                        return;
                    }

                    if (e != ReturnValue.Ok) Trace.TraceWarning("UnitSyncer: Resource registering failed: {0}", e);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error registering resource {0} : {1}", resource.ArchivePath, ex);
            }
        }