Esempio n. 1
0
        private void Initialize()
        {
            if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "nUpdate")))
            {
                try
                {
                    Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "nUpdate", Application.ProductName));
                }
                catch (Exception ex)
                {
                    throw new IOException(String.Format(_lp.MainFolderCreationExceptionText,
                                                        ex.Message));
                }
            }

            string languageFilePath;

            try
            {
                languageFilePath = CultureFilePaths.First(item => item.Key.Equals(LanguageCulture)).Value;
            }
            catch (InvalidOperationException)
            {
                languageFilePath = null;
            }

            if (!String.IsNullOrEmpty(languageFilePath))
            {
                try
                {
                    _lp = Serializer.Deserialize <LocalizationProperties>(File.ReadAllText(languageFilePath));
                }
                catch (Exception)
                {
                    _lp = new LocalizationProperties();
                }
            }
            else if (String.IsNullOrEmpty(languageFilePath) && LanguageCulture.Name != "en")
            {
                string resourceName = String.Format("nUpdate.Core.Localization.{0}.json", LanguageCulture.Name);
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    _lp = Serializer.Deserialize <LocalizationProperties>(stream);
                }
            }
            else if (String.IsNullOrEmpty(languageFilePath) && LanguageCulture.Name == "en")
            {
                _lp = new LocalizationProperties();
            }
        }
Esempio n. 2
0
        private void CheckArguments()
        {
            if (UpdateConfigurationFileUri == null)
            {
                throw new ArgumentException("The property \"UpdateInfoFileUrl\" is not initialized.");
            }

            if (!UpdateConfigurationFileUri.ToString().EndsWith(".json"))
            {
                throw new InvalidJsonFileException("The update configuration file is not a valid JSON-file.");
            }

            if (String.IsNullOrEmpty(PublicKey))
            {
                throw new ArgumentException("The property \"PublicKey\" is not initialized.");
            }

            if (ReferenceEquals(CurrentVersion, null))
            {
                throw new ArgumentException("The current version must have a value.");
            }

            if (LanguageCulture == null)
            {
                throw new ArgumentException("The property \"LanguageCulture\" is not initialized.");
            }

            var existingCultureInfos = new[] { new CultureInfo("en"), new CultureInfo("de-DE"), new CultureInfo("de-AT"), new CultureInfo("de-CH") };

            if (!existingCultureInfos.Any(item => item.Equals(LanguageCulture)) &&
                !CultureFilePaths.ContainsKey(LanguageCulture))
            {
                throw new ArgumentException(
                          "The given culture info does neither exist in nUpdate's resources, nor in property \"CultureFilePaths\".");
            }

            if (UseCustomInstallerUserInterface && String.IsNullOrEmpty(CustomInstallerUiAssemblyPath))
            {
                throw new ArgumentException(
                          "The property \"CustomInstallerUiAssemblyPath\" is not initialized although \"UseCustomInstallerUserInterface\" is set to \"true\"");
            }
        }