Пример #1
0
        internal static void Shutdown()
        {
#if LOCALIZATION
            if (initialized && writeNotFound)
            {
                var fileBase        = Path.Combine(VirtualFileSystem.Directories.EngineInternal, "Localization", language);
                var pathNotFoundTxt = fileBase + "_NotFound.txt";

                EDictionary <string, string> newNotFound = null;
                Encoding encoding = null;
                if (File.Exists(pathNotFoundTxt))
                {
                    ParseFile(language + "_NotFound", out newNotFound, out encoding);
                }

                if (newNotFound == null)
                {
                    newNotFound = new EDictionary <string, string>();
                }

                foreach (var v in notFound)
                {
                    if (!newNotFound.ContainsKey(v))
                    {
                        newNotFound[v] = "";
                    }
                }

                try
                {
                    if (File.Exists(pathNotFoundTxt))
                    {
                        File.Delete(pathNotFoundTxt);
                    }

                    var lines = new List <string>();
                    foreach (var pair in newNotFound)
                    {
                        lines.Add(pair.Key + "|" + pair.Value);
                    }

                    lines.Sort();

                    if (encoding != null)
                    {
                        File.WriteAllLines(pathNotFoundTxt, lines, encoding);
                    }
                    else
                    {
                        File.WriteAllLines(pathNotFoundTxt, lines);
                    }
                }
                catch (Exception e)
                {
                    Log.Warning("EditorLocalization: Shutdown: " + e.Message);
                }
            }
#endif
        }
Пример #2
0
            //

            public Enumerator(EDictionary <TKey, TValue> dictionary)
            {
                this.dictionary = dictionary;
                this.version    = dictionary.version;

                this.orderedIndex = dictionary.orderedStartIndex;
                this.current      = default(KeyValuePair <TKey, TValue>);
            }
Пример #3
0
            public override Metadata.TypeInfo MetadataGetType(string pathInside)
            {
                if (assembly != null)
                {
                    if (typeByPathInside == null)
                    {
                        typeByPathInside = new EDictionary <string, Metadata.TypeInfo>();

                        foreach (var netType in assembly.GetExportedTypes())
                        {
                            var type = MetadataManager.GetTypeOfNetType(netType);                              //, false );

                            //!!!!так?
                            string pathInside2;
                            {
                                int index = type.Name.IndexOf('|');
                                if (index != -1)
                                {
                                    pathInside2 = type.Name.Substring(index + 1);
                                }
                                else
                                {
                                    pathInside2 = "";
                                }
                            }

                            typeByPathInside[pathInside2] = type;
                        }
                    }

                    {
                        Metadata.TypeInfo type;
                        typeByPathInside.TryGetValue(pathInside, out type);
                        return(type);
                    }
                }

                return(base.MetadataGetType(pathInside));
            }
Пример #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;
		}
Пример #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);
        }