Beispiel #1
0
        /// <summary>
        /// Attempts to deserialize a InstallationInfo object from the given directory path,
        /// returns a newly constructed InstallationInfo object otherwise
        ///
        /// Resets/reserializes the InstallationInfo object if needed
        /// </summary>
        /// <param name="path">directory path from which to load the json</param>
        /// <returns></returns>
        public static InstallationInfo LoadFromPath(string path)
        {
            var installInfoPath         = Path.Combine(path, InstallationInfo.InstallationInfoFileName);
            InstallationInfo info       = new InstallationInfo();
            bool             fileExists = File.Exists(installInfoPath);

            if (fileExists)
            {
                var text = File.ReadAllText(installInfoPath, Encoding.UTF8);
                try
                {
                    info = JsonConvert.DeserializeObject <InstallationInfo>(text);
                }
                catch (JsonException)
                {
                    // ignore silently
                }
            }

            bool reset = info.ResetIfMonthChanged();

            if (!fileExists || reset)
            {
                info.JsonSerialize(installInfoPath);
            }
            return(info);
        }