/////////////////////////////////////////// public static bool Init(string fileName, out string error) { error = null; realFileName = VirtualPathUtility.GetRealPathByVirtual(fileName); if (!File.Exists(realFileName)) { textBlock = new TextBlock(); return(true); } textBlock = TextBlockUtility.LoadFromRealFile(realFileName, out error); if (textBlock == null) { return(false); } foreach (Parameter parameter in parameters) { parameter.Load(textBlock); } //!!!! //LoadEvent?.Invoke( /*this, */textBlock, ref error ); //if( !string.IsNullOrEmpty( error ) ) // return false; //if( !parameter.Load( textBlock ) ) // return false; return(true); }
protected override void Load() { if (Owner.LoadedBlock == null) { var settingsFileName = Owner.Name + ".settings"; if (VirtualFile.Exists(settingsFileName)) { //!!!!check errors var block = TextBlockUtility.LoadFromVirtualFile(settingsFileName); Owner.LoadedBlock = block; } else { //!!!!так? var block = new TextBlock(); var child = block.AddChild(".component", MetadataManager.GetTypeOfNetType(typeof(Component_Font)).Name); //default configuration var b1 = child.AddChild("CharacterRanges"); var b2 = b1.AddChild("Value"); b2.SetAttribute("Count", "2"); b2.SetAttribute("0", "32 127"); b2.SetAttribute("1", "160 191"); Owner.LoadedBlock = block; } } base.Load(); }
//!!!!! //static void PreloadFileToMemoryFromBackgroundThread_Function( object data ) //{ // PreloadFileToMemoryItem item = (PreloadFileToMemoryItem)data; // try // { // using( VirtualFileStream stream = VirtualFile.Open( item.Path ) ) // { // byte[] buffer = new byte[ stream.Length ]; // if( stream.Read( buffer, 0, buffer.Length ) != buffer.Length ) // { // throw new Exception( "Unable to load all data." ); // } // item.data = buffer; // item.loaded = true; // } // } // catch( Exception e ) // { // item.error = e.Message; // } //} //public static PreloadFileToMemoryItem PreloadFileToMemoryFromBackgroundThread( string path ) //{ // lock( lockObject ) // { // string pathLowerCase = path.ToLower(); // PreloadFileToMemoryItem item; // if( preloadedFilesToMemory.TryGetValue( pathLowerCase, out item ) ) // return item; // item = new PreloadFileToMemoryItem(); // item.path = path; // preloadedFilesToMemory.Add( pathLowerCase, item ); // //start Task // Task task = new Task( PreloadFileToMemoryFromBackgroundThread_Function, item ); // task.Start(); // return item; // } //} //public static void UnloadPreloadedFileToMemory( string path ) //{ // lock( lockObject ) // { // string pathLowerCase = path.ToLower(); // preloadedFilesToMemory.Remove( pathLowerCase ); // } //} //public static void UnloadPreloadedFileToMemory( PreloadFileToMemoryItem item ) //{ // lock( lockObject ) // { // UnloadPreloadedFileToMemory( item.Path ); // } //} //!!!!! //public static ICollection<Package> Packages //{ // get { return PackageManager.Packages; } //} //public static Package GetPackage( string realFileName ) //{ // lock( lockObject ) // { // return PackageManager.GetPackage( realFileName ); // } //} //public delegate void PackageLoadingDelegate( string realFileName, bool loadInfoOnly, ref Package implemetation, ref string error ); //public static event PackageLoadingDelegate PackageLoading; //internal static void CallPackageLoading( string realFileName, bool loadInfoOnly, ref Package implemetation, ref string error ) //{ // if( PackageLoading != null ) // PackageLoading( realFileName, loadInfoOnly, ref implemetation, ref error ); //} //public delegate void PackageLoadedDelegate( Package package ); //public static event PackageLoadedDelegate PackageLoaded; //internal static void CallPackageLoaded( Package package ) //{ // if( PackageLoaded != null ) // PackageLoaded( package ); //} //public static Package.InfoClass LoadPackageInfo( string realFileName, out string error ) //{ // lock( lockObject ) // { // return PackageManager.LoadPackageInfo( realFileName, out error ); // } //} //public static Package LoadPackage( string realFileName, out string error ) //{ // lock( lockObject ) // { // return PackageManager.LoadPackage( realFileName, out error ); // } //} //!!!!! //public void UnloadPackage(Package package) //{ //} static void InitDefaultSettingsConfig() { if (defaultSettingsConfig == null) { string realFileName = Path.Combine(Directories.Binaries, "NeoAxis.DefaultSettings.config"); if (File.Exists(realFileName)) { defaultSettingsConfig = TextBlockUtility.LoadFromRealFile(realFileName); } else { Log.Warning("VirtualFileSystem: InitDefaultSettingsConfig: \"NeoAxis.DefaultSettings.config\" is not exists."); defaultSettingsConfig = new TextBlock(); } } }
bool InitInternal(string language, bool localizeEngine) { this.language = language; this.localizeEngine = localizeEngine; //alternative loader TextBlock rootBlock = null; bool error2 = false; if (AlternativeLanguageFileLoaderHandler != null) { AlternativeLanguageFileLoaderHandler(ref rootBlock, ref error2); } if (error2) { return(false); } //default loader if (rootBlock == null) { //!!!!локализация дополнений //!!!!!еще можно изменить Engine.language. сделать уровни видать. //!!!!!! string fileName = Path.Combine(Path.Combine(LanguagesDirectory, language), "Engine.language"); if (VirtualFile.Exists(fileName)) { string error; rootBlock = TextBlockUtility.LoadFromVirtualFile(fileName, out error); if (rootBlock == null) { Log.Fatal("Parsing file failed \"{0}\" ({1}).", fileName, error); return(false); } } } if (rootBlock != null) { ParseLanguageTextBlock(rootBlock); } return(true); }
public static string GetParameter(string virtualTextureFileName, string parameterName, out string error) { string fileName = virtualTextureFileName + ".settings"; if (!VirtualFile.Exists(fileName)) { error = ""; return(""); } var block = TextBlockUtility.LoadFromVirtualFile(fileName, out error); if (block == null) { return(""); } error = ""; return(block.GetAttribute(parameterName)); }
protected override void Load() { if (Owner.LoadedBlock == null) { var settingsFileName = Owner.Name + ".settings"; if (VirtualFile.Exists(settingsFileName)) { var block = TextBlockUtility.LoadFromVirtualFile(settingsFileName); Owner.LoadedBlock = block; } else { var block = new TextBlock(); var child = block.AddChild(".component", MetadataManager.GetTypeOfNetType(typeof(Component_Import3D)).Name); Owner.LoadedBlock = block; } } base.Load(); }
static void ReadCachedInfoFile(string destFileNameBase, out string sourceFileHash, out int sourceFileSize) //, out PixelFormat sourceFileFormat ) { sourceFileHash = ""; sourceFileSize = 0; //sourceFileFormat = PixelFormat.Unknown; GetDestFileNames(destFileNameBase, out var infoFileName, out var envFileName, out var irrFileName); if (VirtualFile.Exists(envFileName) && VirtualFile.Exists(irrFileName)) { var block = TextBlockUtility.LoadFromVirtualFile(infoFileName, out _); if (block != null) { try { sourceFileHash = block.GetAttribute("SourceFileHash"); sourceFileSize = int.Parse(block.GetAttribute("SourceFileSize")); //sourceFileFormat = (PixelFormat)Enum.Parse( typeof( PixelFormat ), block.GetAttribute( "SourceFileFormat" ) ); } catch { } } } }
public static bool SetParameter(string virtualTextureFileName, string parameterName, string parameterValue, out string error) { string fileName = virtualTextureFileName + ".settings"; if (!VirtualFile.Exists(fileName) && string.IsNullOrEmpty(parameterValue)) { //no sense to update error = ""; return(true); } TextBlock block = null; if (VirtualFile.Exists(fileName)) { block = TextBlockUtility.LoadFromVirtualFile(fileName, out error); if (block == null) { return(false); } } else { block = new TextBlock(); } if (!string.IsNullOrEmpty(parameterValue)) { block.SetAttribute(parameterName, parameterValue); } else { block.DeleteAttribute(parameterName); } if (block.Children.Count != 0 || block.Attributes.Count != 0) { if (!TextBlockUtility.SaveToVirtualFile(block, fileName, out error)) { return(false); } } else { if (VirtualFile.Exists(fileName)) { try { File.Delete(VirtualPathUtility.GetRealPathByVirtual(fileName)); } catch (Exception e) { error = e.Message; return(false); } } } error = ""; return(true); }
internal static void ParseDisableAssemblyNamespaceRegistration() { disableAssemblyRegistration = new ESet <string>(); disableNamespaceRegistration = new ESet <string>(); string realFileName = Path.Combine(VirtualFileSystem.Directories.Binaries, "NeoAxis.DefaultSettings.config"); if (File.Exists(realFileName)) { var block = TextBlockUtility.LoadFromRealFile(realFileName); if (block != null) { { var groupBlock = block.FindChild("DisableAssemblyRegistration"); if (groupBlock != null) { foreach (var itemBlock in groupBlock.Children) { if (itemBlock.Name == "Assembly") { bool disable = true; var platform = itemBlock.GetAttribute("Platform"); if (!string.IsNullOrEmpty(platform)) { if (string.Compare(SystemSettings.CurrentPlatform.ToString(), platform, true) != 0) { disable = false; } } if (disable) { var name = itemBlock.GetAttribute("Name"); disableAssemblyRegistration.AddWithCheckAlreadyContained(name); } } } } } { var groupBlock = block.FindChild("DisableNamespaceRegistration"); if (groupBlock != null) { foreach (var itemBlock in groupBlock.Children) { if (itemBlock.Name == "Namespace") { bool disable = true; var platform = itemBlock.GetAttribute("Platform"); if (!string.IsNullOrEmpty(platform)) { if (string.Compare(SystemSettings.CurrentPlatform.ToString(), platform, true) != 0) { disable = false; } } if (disable) { var name = itemBlock.GetAttribute("Name"); disableNamespaceRegistration.AddWithCheckAlreadyContained(name); } } } } } } } else { Log.Warning("AssemblyUtility: ParseDisableAssemblyNamespaceRegistration: \"NeoAxis.DefaultSettings.config\" is not exists."); } }
static bool Generate(string sourceFileName, string sourceFileHash, int sourceFileSize, int specifiedSize, out string error) { var text = $"Generating cubemap \"{Path.GetFileName( sourceFileName )}\"..."; var notification = Editor.ScreenNotifications.ShowSticky(text); var destFileNameBase = GetDestFileNameBase(sourceFileName); GetDestFileNames(destFileNameBase, out var infoFileName, out var envFileName, out var irrFileName); string temporaryGeneratedFile = ""; try { var sourceRealFileName = VirtualPathUtility.GetRealPathByVirtual(sourceFileName); { //convert .image to 6 face HDR image if (Path.GetExtension(sourceRealFileName) == ".image") { var image = ResourceManager.LoadResource <Component_Image>(sourceFileName, out error); if (image == null) { return(false); } string[] loadCubeMap6Files = null; string loadFromOneFile = null; { if (image.AnyCubemapSideIsSpecified()) { if (image.AllCubemapSidesAreaSpecified()) { loadCubeMap6Files = new string[6]; for (int n = 0; n < 6; n++) { var v = image.GetLoadCubeSide(n); if (v != null) { loadCubeMap6Files[n] = v.ResourceName; } if (string.IsNullOrEmpty(loadCubeMap6Files[n]) || !VirtualFile.Exists(loadCubeMap6Files[n])) { loadCubeMap6Files = null; break; } } } } else { var v = image.LoadFile.Value; loadFromOneFile = v != null ? v.ResourceName : ""; if (string.IsNullOrEmpty(loadFromOneFile) || !VirtualFile.Exists(loadFromOneFile)) { loadFromOneFile = null; } } } if (loadFromOneFile != null) { sourceRealFileName = VirtualPathUtility.GetRealPathByVirtual(loadFromOneFile); } else if (loadCubeMap6Files != null) { temporaryGeneratedFile = Path.GetTempPath() + Guid.NewGuid().ToString() + ".hdr"; sourceRealFileName = temporaryGeneratedFile; ImageUtility.Image2D image2D = null; for (int face = 0; face < 6; face++) { if (!ImageUtility.LoadFromVirtualFile(loadCubeMap6Files[face], out var data, out var size, out _, out var format, out _, out _, out error)) { return(false); } if (image2D == null) { image2D = new ImageUtility.Image2D(PixelFormat.Float32RGB, size * new Vector2I(4, 3)); } Vector2I index = Vector2I.Zero; switch (face) { case 0: index = new Vector2I(2, 1); break; case 1: index = new Vector2I(0, 1); break; case 2: index = new Vector2I(1, 0); break; case 3: index = new Vector2I(1, 2); break; case 4: index = new Vector2I(1, 1); break; case 5: index = new Vector2I(3, 1); break; } var faceImage = new ImageUtility.Image2D(format, size, data); image2D.Blit(index * size, faceImage); } if (!ImageUtility.Save(temporaryGeneratedFile, image2D.Data, image2D.Size, 1, image2D.Format, 1, 0, out error)) { return(false); } } else { error = "The image wrong configured."; return(false); } } } int sizeEnv = 32; if (specifiedSize == 0) { //detect size if (!ImageUtility.LoadFromRealFile(sourceRealFileName, out _, out var sourceSize, out _, out _, out _, out _, out error)) { return(false); } //!!!!если кубемапа if (Math.Abs((double)sourceSize.X / (double)sourceSize.Y - 1.333333) <= 0.001) { sizeEnv = sourceSize.X / 4; } else { //!!!! sizeEnv = MathEx.NextPowerOfTwo(sourceSize.X / 3); } if (sizeEnv == 0) { sizeEnv = 1; } } else { sizeEnv = specifiedSize; } int sizeIrr = 32; var destRealFileNameBase = VirtualPathUtility.GetRealPathByVirtual(destFileNameBase); var infoRealFileName = VirtualPathUtility.GetRealPathByVirtual(infoFileName); var envRealFileName = VirtualPathUtility.GetRealPathByVirtual(envFileName); var irrRealFileName = VirtualPathUtility.GetRealPathByVirtual(irrFileName); //delete old files if (File.Exists(infoRealFileName)) { File.Delete(infoRealFileName); } if (File.Exists(envRealFileName)) { File.Delete(envRealFileName); } if (File.Exists(irrRealFileName)) { File.Delete(irrRealFileName); } var destDirectory = Path.GetDirectoryName(destRealFileNameBase); if (!Directory.Exists(destDirectory)) { Directory.CreateDirectory(destDirectory); } var irradianceValues = new List <Vector3>(); if (!GenerateFile(sourceRealFileName, false, sizeEnv, envRealFileName, irradianceValues, out error)) { return(false); } if (!GenerateFile(sourceRealFileName, true, sizeIrr, irrRealFileName, null, out error)) { return(false); } //make .info file { var block = new TextBlock(); block.SetAttribute("SourceFileHash", sourceFileHash); block.SetAttribute("SourceFileSize", sourceFileSize.ToString()); //block.SetAttribute( "SourceFileFormat", sourceFileFormat.ToString() ); for (int n = 0; n < irradianceValues.Count; n++) { block.SetAttribute("Irradiance" + n.ToString(), irradianceValues[n].ToString()); } if (!TextBlockUtility.SaveToRealFile(block, infoRealFileName, out error)) { return(false); } } } catch (Exception e) { error = e.Message; return(false); } finally { notification.Close(); try { if (File.Exists(temporaryGeneratedFile)) { File.Delete(temporaryGeneratedFile); } } catch { } } error = ""; return(true); }
protected virtual void Load() { //override behavior by event if (ResultObject == null) { bool handled = false; LoadOverride?.Invoke(this, ref handled); if (handled) { return; } } //default behavior if (ResultObject == null) { //load block if (Owner.LoadedBlock == null) { string error; Owner.LoadedBlock = TextBlockUtility.LoadFromVirtualFile(Owner.Name, out error); if (Owner.LoadedBlock == null) { //!!!! // comment this fatal ! //Log.Fatal( error ); //TODO: also we can use exceptions! //throw new Exception( error ); StatusError = error; Status = StatusEnum.Error; return; } } //parse text block string error2; var component = ComponentUtility.LoadComponentFromTextBlock(null, Owner.LoadedBlock, Owner.Name, this, componentSetEnabled, componentCreateHierarchyController, out error2); //var component = ComponentUtils.LoadComponentFromTextBlock( Owner.LoadedBlock, Owner.Name, null, out error2 ); if (component == null) { ////!!!!!!! //Log.Fatal( "impl" ); //!!!!! StatusError = error2; Status = StatusEnum.Error; return; } //!!!! //if( componentSetEnabled != null ) // component.Enabled = componentSetEnabled.Value; //xx xx; //xx xx;//сначала выключить иерархию? потом всем разом включится? ////!!!!возможно это раньше нужно делать, т.к. в GetProvidedType() что-то там надо //if( componentCreateHierarchyController ) // ComponentUtils.CreateHierarchyControllerForRootComponent( component, this, true );//, true ); //resource is ready //ResultObject = component; Status = StatusEnum.Ready; } }
public static bool ParseFile( string fileName, out EDictionary<string, string> resultData, out Encoding encoding, out bool wide ) { resultData = null; encoding = null; wide = false; var fileBase = Path.Combine( VirtualFileSystem.Directories.EngineInternal, "Localization", fileName ); var pathInfo = fileBase + ".info"; var pathTxt = fileBase + ".txt"; if( File.Exists( pathTxt ) ) { try { string encodingName = null; int? encodingCodepage = null; if( File.Exists( pathInfo ) ) { var block = TextBlockUtility.LoadFromRealFile( pathInfo ); if( block != null ) { //Encoding { var value = block.GetAttribute( "Encoding" ); if( int.TryParse( value, out var codepage ) ) encodingCodepage = codepage; else encodingName = value; } //WideLanguage { var value = block.GetAttribute( "WideLanguage" ); if( !string.IsNullOrEmpty( value ) ) wide = (bool)SimpleTypes.ParseValue( typeof( bool ), value ); } } } #if !DEPLOY if( encodingCodepage.HasValue ) encoding = CodePagesEncodingProvider.Instance.GetEncoding( encodingCodepage.Value ); else if( !string.IsNullOrEmpty( encodingName ) ) encoding = CodePagesEncodingProvider.Instance.GetEncoding( encodingName ); #endif //if( encodingCodepage.HasValue ) // encoding = Encoding.GetEncoding( encodingCodepage.Value ); //else if( !string.IsNullOrEmpty( encodingName ) ) // encoding = Encoding.GetEncoding( encodingName ); string[] lines = null; if( encoding != null ) lines = File.ReadAllLines( pathTxt, encoding ); else lines = File.ReadAllLines( pathTxt ); resultData = new EDictionary<string, string>(); foreach( var line in lines ) { if( !string.IsNullOrEmpty( line ) ) { var strs = line.Split( new char[] { '|' } ); if( strs.Length != 3 ) throw new Exception( string.Format( "Invalid format for line \'{0}\'.", line ) ); resultData[ strs[ 0 ] + "|" + strs[ 1 ] ] = strs[ 2 ]; } } return true; } catch( Exception e ) { Log.Warning( e.Message ); } } return false; }
public static bool ParseFile(string fileName, out EDictionary <string, string> resultData, out Encoding encoding) { resultData = null; encoding = null; var fileBase = Path.Combine(VirtualFileSystem.Directories.EngineInternal, "Localization", fileName); var pathInfo = fileBase + ".info"; var pathTxt = fileBase + ".txt"; if (File.Exists(pathTxt)) { try { string encodingName = null; int? encodingCodepage = null; if (File.Exists(pathInfo)) { var block = TextBlockUtility.LoadFromRealFile(pathInfo); if (block != null) { var value = block.GetAttribute("Encoding"); if (int.TryParse(value, out var codepage)) { encodingCodepage = codepage; } else { encodingName = value; } } } if (encodingCodepage.HasValue) { encoding = Encoding.GetEncoding(encodingCodepage.Value); } else if (!string.IsNullOrEmpty(encodingName)) { encoding = Encoding.GetEncoding(encodingName); } string[] lines = null; if (encoding != null) { lines = File.ReadAllLines(pathTxt, encoding); } else { lines = File.ReadAllLines(pathTxt); } resultData = new EDictionary <string, string>(); foreach (var line in lines) { if (!string.IsNullOrEmpty(line)) { var strs = line.Split(new char[] { '|' }); if (strs.Length != 3) { throw new Exception(string.Format("Invalid format for line \'{0}\'.", line)); } resultData[strs[0] + "|" + strs[1]] = strs[2]; } } return(true); } catch (Exception e) { Log.Warning(e.Message); } } return(false); }