// Program.cs created with MonoDevelop
//
// Copyright (C) 2018  Thomas Klose & Torsten Schache, Hiperscan GmbH Dresden, Germany
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License version 3
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, see http://www.gnu.org/licenses or write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA, 02110-1301 USA
//

using System;
using Hiperscan.UpdateCertificate;
using Hiperscan.Common.RegistryManagement;
using Hiperscan.AnalysisModule;

namespace Hiperscan.UpdateCertificateStarter
{
    class MainClass
    {
        public static void Main(string[] args)  
        {
            try
            {
                MSRegistry registry = MSRegistry.Create();

                HSRegistryEntry quantifier = registry.QuantifierModule;
                HSRegistryEntry identifier = registry.IdentModule;
                HSRegistryEntry current = null;

                AnalysisType analysis_type = AnalysisType.None;
                if (quantifier.HasRegistryEntry)
                {
                    analysis_type = AnalysisType.Quantification;
                    current = quantifier;
                }

                if (identifier.HasRegistryEntry && identifier.InstallDate > quantifier.InstallDate)
                {
                    analysis_type = AnalysisType.Identification;
                    current = identifier;
                }

                UpdateCertificateDrawer.Run(current.FullVersion,
                                            current.InstallDate,
                                            analysis_type,
                                            current.Locale);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot create update certificate: {0}", ex);
            }
        }
    }
}
