Esempio n. 1
0
        ///////////////////////////////////////////

        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);
        }
Esempio n. 2
0
        //!!!!!

        //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();
                }
            }
        }
Esempio n. 3
0
        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.");
            }
        }
Esempio n. 4
0
		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;
		}
Esempio n. 5
0
        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);
        }