示例#1
0
        public static void LoadContent(bool immediate)
        {
            if (ShouldReportMissing)
            {
                if (reportWriter == null)
                {
                    reportPath = ReportFile;
                    try
                    {
                        reportWriter = Storage4.OpenStreamWriter(reportPath);
                    }
                    catch (Exception e)
                    {
                        if (e != null)
                        {
                        }

#if NETFX_CORE
                        MessageDialog dialog = new MessageDialog("reportPath = " + reportPath + "\nLoadContent failure in Localizer.");
#else
                        System.Windows.Forms.MessageBox.Show(
                            "reportPath = " + reportPath,
                            "LoadContent failure in Localizer.",
                            System.Windows.Forms.MessageBoxButtons.OK,
                            System.Windows.Forms.MessageBoxIcon.Asterisk);
#endif
                    }
                }
            }
        }
示例#2
0
        }   // end of GetFullPath()

        static private TextWriter OpenFile(string fullPath)
        {
            TextWriter tw = null;

#if NETFX_CORE
            tw = Storage4.OpenStreamWriter(fullPath);
#else
            tw = new StreamWriter(fullPath);
#endif

            return(tw);
        }   // end of OpenFile
示例#3
0
            public void Update(string language, string newResource)
            {
                var resourcePath = Path.Combine(LanguageDir, language, Name);
                var resourceXml  = XDocument.Load(XmlReader.Create(new StringReader(newResource)));

                Encoding encoding = null;

                // Ensure that the declared XML encoding is used while saving the file when available
                if (resourceXml.Declaration != null && !string.IsNullOrEmpty(resourceXml.Declaration.Encoding))
                {
                    encoding = GetEncoding(resourceXml.Declaration.Encoding);
                }
                using (var streamWriter = Storage4.OpenStreamWriter(resourcePath, encoding))
                {
                    streamWriter.Write(newResource);
                }
            }
示例#4
0
        /// <summary>
        /// Given a stream containing Locales.xml data, tries to to update the List of supported Locales
        /// </summary>
        private static void PopulatesLocalesFromXmlStream(Stream localesXmlStream, bool persistFile = false)
        {
            // DebugLog.WriteLine("PopulatesLocalesFromXmlStream()");
            // DebugLog.WriteLine("    localesXmlStream : " + (localesXmlStream == null ? "null" : "valid"));
            if (localesXmlStream == null)
            {
#if LOCALES_DEBUG
                LocalesDebugPrint("localesXmlStream == null in PopulatesLocalesFromXmlStream()");
#endif
                return;
            }

            using (localesXmlStream)
                using (var streamReader = new StreamReader(localesXmlStream))
                {
                    var localesXml = streamReader.ReadToEnd();
                    if (string.IsNullOrEmpty(localesXml))
                    {
                        // DebugLog.WriteLine("    null read.  Returning.");
                        return;
                    }

                    var localesXmlParser = new LocalesXmlParser();
                    var locales          = localesXmlParser.Parse(localesXml);

                    // DebugLog.WriteLine("    filtering, count = " + locales.Count.ToString());
                    // If the localized version of the language name isn't supported by
                    // out current font set then remove it from the list.  This will
                    // prevent people with older versions of Kodu from trying to select
                    // languages that can't be displayed (eg with Asian fonts).
                    //
                    // Loop over the list backwards so we safely remove elements without
                    // losing our place.
                    for (int i = locales.Count - 1; i >= 0; i--)
                    {
                        if (!TextHelper.StringIsValid(locales[i].Native))
                        {
                            locales.RemoveAt(i);
                        }
                    }

                    Debug.Assert(locales.Count > 0, "Why aren't we seeing files from the localization server?");

                    if (locales == null)
                    {
                        // DebugLog.WriteLine("    done filtering, locales = null");
                    }
                    else
                    {
                        // DebugLog.WriteLine("    done filtering, count = " + locales.Count.ToString());
                    }

                    if (locales != null && locales.Count > 0)
                    {
                        Locales = locales;

                        if (!persistFile)
                        {
                            return;
                        }

                        // DebugLog.WriteLine("    persisting to : " + LocalesFilePath);
                        using (var streamWriter = Storage4.OpenStreamWriter(LocalesFilePath))
                        {
                            streamWriter.Write(localesXml);
                        }
                    }
                }
        }