private static BitmapSource CreateCamouflagePreview(LocalGameClient client, Camouflage camouflage, WpfColor baseColor) { if (!PackageStream.IsFileExisted(client.PackageIndexer, camouflage.Texture)) { return(null); } var image = new Image(); image.Width = 64; image.Height = 64; using (var stream = new PackageStream(client.PackageIndexer, camouflage.Texture)) { image.Source = (new DDSImage(stream)).BitmapSource(0); } var colors = camouflage.GetColors(); image.Effect = new CamouflageEffect() { BaseColor = baseColor, Color1 = colors[0], Color2 = colors[1], Color3 = colors[2], Color4 = colors[3], }; image.MeasureAndArrange(); var imageSource = image.RenderToBitmap(); imageSource.Freeze(); return(imageSource); }
public void FullyLoad() { Log.InfoFormat("fully loading database: version='{0}', nationName='{1}'", this.Version, this.RootPath); if (this.IsFullyLoaded) { Log.Info("this database is already fully loaded"); return; } //this.ReadVersion(); this.InitializePackages(); var scriptEntries = PackageStream.GetFileEntries(Path.Combine(RootPath, ScriptsPackageFile)); var nationEntries = scriptEntries.Where(s => s.StartsWith(VehiclesFolderInPackage) && s.Length > VehiclesFolderInPackage.Length).Select(s => s.Substring(VehiclesFolderInPackage.Length, s.IndexOf("/", VehiclesFolderInPackage.Length, StringComparison.InvariantCulture) - VehiclesFolderInPackage.Length)).Distinct(); foreach (var nationName in nationEntries) { if (Database.IsTechTreeFolder(nationName, scriptEntries)) { var nation = new NationalDatabase(this, nationName); Log.InfoFormat("adding nation database: {0}", nation.Key); this.Nations.Add(nation.Key, nation); } } this.LoadCommonData(); this.LoadBenchmarkTanks(); this.IsFullyLoaded = true; }
public static ImageSource Load(string packagePath, string localPath, double dpi = 96) { return(s_packageImageCache.GetOrCreate(UnifiedPath.Combine(packagePath, localPath), () => { try { using (var stream = new PackageStream(packagePath, localPath)) { BitmapSource image = BitmapImageEx.FromStream(stream); if (image.DpiX != dpi || image.DpiY != dpi) { image = image.ChangeDPI(dpi); } image.Freeze(); return (ImageSource)image; } } catch (Exception) { return null; } })); }
private static void SetImageSource(ImageBrush brush, PackageFileInfo path) { ImageSource ddsSource; if (!_materialImages.TryGetValue(path.ToString(), out ddsSource)) { string packagePath; if (!PackageStream.IsFileExisted(path.PackagePath, path.FileInPackagePath)) { packagePath = Path.Combine(Path.GetFullPath(Path.GetDirectoryName(path.PackagePath)), "shared_content.pkg"); } else { packagePath = path.PackagePath; } using (var Stream = new PackageStream(packagePath, path.FileInPackagePath)) { var dds = new DDSImage(Stream); ddsSource = dds.BitmapSource(0); } } brush.ImageSource = ddsSource; }
protected override void Dispose(bool disposing) { foreach (Stream s in PartStreams.Values) { s.Close(); } PackageStream.Close(); }
private PackageStream OpenPrimitiveFile(string modelFile) { var primitiveFile = Path.ChangeExtension(modelFile, ".primitives"); // pre 10.0 if (!PackageStream.IsFileExisted(this.Database.PackageDatabase, primitiveFile)) { primitiveFile = Path.ChangeExtension(modelFile, ".primitives_processed"); // post 10.0 } return(new PackageStream(this.Database.PackageDatabase, primitiveFile)); }
private PackageStream OpenVisualFile(string modelFile) { var visualFile = Path.ChangeExtension(modelFile, ".visual"); // pre 10.0 if (!PackageStream.IsFileExisted(this.Database.PackageDatabase, visualFile)) { visualFile = Path.ChangeExtension(modelFile, ".visual_processed"); // post 10.0 } return(new PackageStream(this.Database.PackageDatabase, visualFile)); }
private ImageSource LoadTankIcon(string relativePath, string hyphenKey) { var localPath = string.Format("{0}/{1}.png", relativePath, hyphenKey); if (PackageStream.IsFileExisted(_paths.GuiPackageFile, localPath)) { return(PackageImage.Load(_paths.GuiPackageFile, localPath)); } localPath = string.Format("{0}/noImage.png", relativePath); return(PackageImage.Load(_paths.GuiPackageFile, localPath)); }
protected override void Dispose(bool disposing) { foreach (Stream s in PartStreams.Values) { s.Close(); } base.Dispose(disposing); if (OwnsStream) { PackageStream.Close(); } }
private string GetPackagePath(string filename, string declaredPackagePath) { string actualPackagePath; if (!PackageStream.IsFileExisted(declaredPackagePath, filename)) { actualPackagePath = Path.Combine(Path.GetFullPath(Path.GetDirectoryName(declaredPackagePath)), "shared_content.pkg"); } else { actualPackagePath = declaredPackagePath; } return(actualPackagePath); }
public static void GH3MusicPlayerOnCustomFolder(string FileInGameData, string Track) { if (File.Exists(FileInGameData)) { using (PackageStream IEFContainer = new PackageStream(FileInGameData)) { HostedStream MusicToPlay = IEFContainer.GetContainedFileStream(Track); SoundPlayer Player = new SoundPlayer(MusicToPlay); Player.PlayLooping(); } } else { Velotage3DGameEngine.ExceptionManager.GetException.Exception(ExceptionManager.ErrorList.ErrorLoadingToRam); } }
/// <summary> /// Called every time this plugin is run in the workflow execution. /// </summary> public void Execute() { // HOWTO: Use this to show the progress of a plugin algorithm execution in the editor. ProgressChanged(1, 100); if (IsValidIP(settings.DeviceIP)) { // Init endPoint = new IPEndPoint(IPAddress.Parse(settings.DeviceIP), settings.Port); clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); using (CStreamReader streamReader = PackageStream.CreateReader()) { packetData = new byte[1024]; while ((bytesRead = streamReader.Read(packetData)) > 0) { var input = new List <byte>(); // Note: buffer can contain less data than buffer.Length, therefore consider bytesRead foreach (var zero in packetData) { if (zero != 0) { input.Add(zero); } else { break; } } clientSocket.SendTo(input.ToArray(), endPoint); } } } else { GuiLogMessage("Ungueltige IP!", NotificationLevel.Error); } // HOWTO: Make sure the progress bar is at maximum when your Execute() finished successfully. ProgressChanged(1, 1); }
public static void GH3MusicPlayer(string GameContent, string FileInsideContainer) { string FileToLoad = Velotage3DGameEngine.EngineInfo.EngineInfo.GetGameDataFolder() + @"VelotageMusic/" + GameContent; if (File.Exists(FileToLoad)) { using (PackageStream IEFContainer = new PackageStream(FileToLoad)) { HostedStream MusicToPlay = IEFContainer.GetContainedFileStream(FileInsideContainer); SoundPlayer Player = new SoundPlayer(MusicToPlay); Player.PlayLooping(); } } else { Velotage3DGameEngine.ExceptionManager.GetException.Exception(ExceptionManager.ErrorList.ErrorLoadingToRam); } }
protected override void FlushCore() { // Ensure that all the data has been read out of the package // stream already. Otherwise we'll lose data when we recreate the zip foreach (ZipPackagePart part in Parts.Values) { if (part.Package != null) { part.GetStream().Dispose(); } } // Empty the package stream PackageStream.Position = 0; PackageStream.SetLength(0); // Recreate the zip file using (ZipArchive archive = new ZipArchive(PackageStream, Append.Create, false)) { // Write all the part streams foreach (ZipPackagePart part in Parts.Values) { if (part.Package == null) { continue; } Stream partStream = part.GetStream(); partStream.Seek(0, SeekOrigin.Begin); using (Stream destination = archive.GetStream(part.Uri.ToString().Substring(1), part.CompressionOption)) { int count = (int)Math.Min(2048, partStream.Length); byte[] buffer = new byte [count]; while ((count = partStream.Read(buffer, 0, buffer.Length)) != 0) { destination.Write(buffer, 0, count); } } } using (Stream s = archive.GetStream(ContentUri, CompressionOption.Maximum)) WriteContentType(s); } }
private void Load() { using ( var stream = new PackageStream(this.Database.PackageDatabase, this.Nation.GetPackageFileName(this.Key + ".xml"))) { using (var reader = new BigworldXmlReader(stream)) { reader.ReadStartElement(); this.Deserialize(reader); reader.ReadEndElement(); } } this.BattleTiers = BattleTierRules.Current.GetBattleTiers(this); this.CamouflageValue = CamouflageValues.Current.GetCamouflageValue(this); _isLoaded = true; }
protected override void Dispose(bool disposing) { foreach (Stream s in PartStreams.Values) { s.Close(); } if (Archive != null) // GZE fixed bug where Archive == null { Archive.Close(); } base.Dispose(disposing); if (OwnsStream) { PackageStream.Close(); } }
private bool PackageFileEquals(string oldLocalPath, string newLocalPath) { var oldPackagePath = this.ReferenceClient.PackageIndexer.GetPackagePath(oldLocalPath); var newPackagePath = this.TargetClient.PackageIndexer.GetPackagePath(newLocalPath); if (oldPackagePath == null && newPackagePath == null) { return(true); } else if (oldPackagePath == null || newPackagePath == null) { return(false); } var oldCrc = PackageStream.GetCrc(oldPackagePath, oldLocalPath); var newCrc = PackageStream.GetCrc(newPackagePath, newLocalPath); return(oldCrc == newCrc); }
public bool TryOpenRead(string path, out Stream stream) { if (this.Source == FileSource.ModFolder) { var modFile = Path.Combine(this.Client.ModDirectory, path); if (File.Exists(modFile)) { stream = File.OpenRead(modFile); return(true); } } if (PackageStream.IsFileExisted(this.Client.PackageIndexer, path)) { stream = new PackageStream(this.Client.PackageIndexer, path); return(true); } stream = null; return(false); }
protected override void FlushCore() { // Ensure that all the data has been read out of the package // stream already. Otherwise we'll lose data when we recreate the zip foreach (ZipPackagePart part in Parts.Values) { part.GetStream(); } if (!PackageStream.CanSeek) { return; } // Empty the package stream PackageStream.Position = 0; PackageStream.SetLength(0); // Recreate the zip file using (ZipStorer archive = ZipStorer.Create(PackageStream, "", false)) { // Write all the part streams foreach (ZipPackagePart part in Parts.Values) { Stream partStream = part.GetStream(); partStream.Seek(0, SeekOrigin.Begin); archive.AddStream(ZipStorer.Compression.Deflate, part.Uri.ToString().Substring(1), partStream, DateTime.UtcNow, ""); } using (var ms = new MemoryStream()) { WriteContentType(ms); ms.Seek(0, SeekOrigin.Begin); archive.AddStream(ZipStorer.Compression.Deflate, ContentUri, ms, DateTime.UtcNow, ""); } } }
private void LoadTankInfo() { Log.Info("loading tank info"); this.TankInfoCollection = new List <TankInfo>(); using (var stream = new PackageStream(this.Database.PackageDatabase, this.GetPackageFileName("list.xml"))) { using (var reader = new BigworldXmlReader(stream)) { reader.ReadStartElement("FromStream"); while (reader.IsStartElement()) { var tankInfo = new TankInfo(this); tankInfo.Deserialize(reader); this.TankInfoCollection.Add(tankInfo); } reader.ReadEndElement(); } } }
private PackageIndexEntry[] BuildPackageIndices() { var entries = new List <PackageIndexEntry>(); foreach (var packageFile in _client.Paths.ClientPackages) { this.LogInfo("buiding package indices for '{0}'", packageFile); var fileEntries = PackageStream.GetFileEntries(packageFile); if (fileEntries == null) { this.LogError("non-existed or invalid package file: {0}", packageFile); continue; } foreach (var filePath in fileEntries) { entries.Add(new PackageIndexEntry(filePath.ToLower(), packageFile)); } } return(entries.ToArray()); }
/// <summary> /// Called every time this plugin is run in the workflow execution. /// </summary> public void Execute() { ProgressChanged(1, 100); //get or create Connection if (ConnectionIDInput == 0) { var con = TryCreateNewConnection(); if (con == null) { GuiLogMessage("Could not create a network connection", NotificationLevel.Error); return; } ConnectionIDInput = availableConnections.AddConnection(con); } var connection = availableConnections.GetConnection(ConnectionIDInput); //chop and send data using (var streamReader = PackageStream.CreateReader()) { var streamBuffer = new byte[65507]; int bytesRead; while ((bytesRead = streamReader.Read(streamBuffer)) > 0) { var packetData = new byte[bytesRead]; Array.Copy(streamBuffer, packetData, bytesRead); if (TrySendData(connection, packetData, bytesRead)) { UpdateOutputs(connection.ID); UpdatePresentation(packetData, connection.RemoteEndPoint); } } } ProgressChanged(1, 1); }
void LoadParts() { parts = new Dictionary <Uri, ZipPackagePart>(new UriComparer()); try { PackageStream.Seek(0, SeekOrigin.Begin); if (Archive == null) { Archive = ZipStorer.Open(PackageStream, FileAccess.Read, false); } List <ZipStorer.ZipFileEntry> dir = Archive.ReadCentralDir(); // Load the content type map file XmlDocument doc = new XmlDocument(); var content = dir.FirstOrDefault(x => x.FilenameInZip == ContentUri); using (var ms = new MemoryStream()) { Archive.ExtractFile(content, ms); ms.Seek(0, SeekOrigin.Begin); doc.Load(ms); } XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable); manager.AddNamespace("content", ContentNamespace); // The file names in the zip archive are not prepended with '/' foreach (var file in dir) { if (file.FilenameInZip.Equals(ContentUri, StringComparison.Ordinal)) { continue; } XmlNode node; if (file.FilenameInZip == RelationshipUri.ToString().Substring(1)) { CreatePartCore(RelationshipUri, RelationshipContentType, CompressionOption.Normal); continue; } string xPath = string.Format("/content:Types/content:Override[@PartName='/{0}']", file); node = doc.SelectSingleNode(xPath, manager); if (node == null) { string ext = Path.GetExtension(file.FilenameInZip); if (ext.StartsWith(".")) { ext = ext.Substring(1); } xPath = string.Format("/content:Types/content:Default[@Extension='{0}']", ext); node = doc.SelectSingleNode(xPath, manager); } // What do i do if the node is null? This means some has tampered with the // package file manually if (node != null) { CreatePartCore(new Uri("/" + file, UriKind.Relative), node.Attributes["ContentType"].Value, CompressionOption.Normal); } } } catch { // The archive is invalid - therefore no parts } }
public void Dispose() { PackageStream?.Dispose(); PackageReader?.Dispose(); }