<commit_before>﻿// ReSharper disable HeuristicUnreachableCode
// ReSharper disable CSharpWarnings::CS0162
namespace SIM.Tool
{
  using System;
  using System.ComponentModel;
  using System.Diagnostics;
  using System.IO;
  using System.Linq;
  using System.Reflection;
  using System.Security.Principal;
  using System.ServiceProcess;
  using System.Threading;
  using System.Windows;
  using System.Xml;
  using SIM.Adapters.SqlServer;
  using SIM.Core;
  using SIM.Core.Common;
  using SIM.Instances;
  using SIM.Pipelines;
  using SIM.Pipelines.Processors;
  using SIM.Tool.Base;
  using SIM.Tool.Base.Plugins;
  using SIM.Tool.Base.Profiles;
  using SIM.Tool.Base.Runtime;
  using SIM.Tool.Windows;
  using SIM.Tool.Wizards;
  using Sitecore.Diagnostics.Base;
  using Sitecore.Diagnostics.Base.Annotations;
  using Sitecore.Diagnostics.Logging;
  using File = System.IO.File;

  public partial class App
  {
    #region Fields

    public static readonly int APP_DUPLICATE_EXIT_CODE = -8;
    public static readonly int APP_NO_MAIN_WINDOW = -44;
    public static readonly int APP_NO_PERMISSIONS = -66;
    public static readonly int APP_NO_IIS = -88;
    public static readonly int APP_PIPELINES_ERROR = -22;
    private static readonly string AppLogsMessage = "The application will be suspended, look at the " + ApplicationManager.LogsFolder + " log file to find out what has happened";

    #endregion

    #region Properties

    #endregion

    #region Methods

    #region Public methods

    public static string GetLicensePath()
    {
      return Path.Combine(ApplicationManager.DataFolder, "license.xml");
    }

    public static string GetRepositoryPath()
    {
      string path = Path.Combine(ApplicationManager.DataFolder, "Repository");
      FileSystem.FileSystem.Local.Directory.Ensure(path);
      return path;
    }

    #endregion

    #region Protected methods

    protected override void OnExit(ExitEventArgs e)
    {
      LifeManager.ReleaseSingleInstanceLock();
      base.OnExit(e);
    }

    protected override void OnStartup([CanBeNull] StartupEventArgs e)
    {
      base.OnStartup(e);

      if (CoreApp.IsFirstRun)
      {
        CacheManager.ClearAll();

        foreach (var filePath in Directory.GetFiles(".", "*-xml", SearchOption.AllDirectories))
        {
          if (filePath == null)
          {
            continue;
          }

          var newFilePath = filePath.Substring(0, filePath.Length - 4) + ".xml";
          if (File.Exists(newFilePath))
          {
            File.Delete(newFilePath);
          }

          File.Move(filePath, newFilePath);
        }
      }<commit_msg>Added Temp folder cleanup during first run of the new version<commit_after>﻿// ReSharper disable HeuristicUnreachableCode
// ReSharper disable CSharpWarnings::CS0162
namespace SIM.Tool
{
  using System;
  using System.ComponentModel;
  using System.Diagnostics;
  using System.IO;
  using System.Linq;
  using System.Reflection;
  using System.Security.Principal;
  using System.ServiceProcess;
  using System.Threading;
  using System.Windows;
  using System.Xml;
  using SIM.Adapters.SqlServer;
  using SIM.Core;
  using SIM.Core.Common;
  using SIM.Instances;
  using SIM.Pipelines;
  using SIM.Pipelines.Processors;
  using SIM.Tool.Base;
  using SIM.Tool.Base.Plugins;
  using SIM.Tool.Base.Profiles;
  using SIM.Tool.Base.Runtime;
  using SIM.Tool.Windows;
  using SIM.Tool.Wizards;
  using Sitecore.Diagnostics.Base;
  using Sitecore.Diagnostics.Base.Annotations;
  using Sitecore.Diagnostics.Logging;
  using File = System.IO.File;

  public partial class App
  {
    #region Fields

    public static readonly int APP_DUPLICATE_EXIT_CODE = -8;
    public static readonly int APP_NO_MAIN_WINDOW = -44;
    public static readonly int APP_NO_PERMISSIONS = -66;
    public static readonly int APP_NO_IIS = -88;
    public static readonly int APP_PIPELINES_ERROR = -22;
    private static readonly string AppLogsMessage = "The application will be suspended, look at the " + ApplicationManager.LogsFolder + " log file to find out what has happened";

    #endregion

    #region Properties

    #endregion

    #region Methods

    #region Public methods

    public static string GetLicensePath()
    {
      return Path.Combine(ApplicationManager.DataFolder, "license.xml");
    }

    public static string GetRepositoryPath()
    {
      string path = Path.Combine(ApplicationManager.DataFolder, "Repository");
      FileSystem.FileSystem.Local.Directory.Ensure(path);
      return path;
    }

    #endregion

    #region Protected methods

    protected override void OnExit(ExitEventArgs e)
    {
      LifeManager.ReleaseSingleInstanceLock();
      base.OnExit(e);
    }

    protected override void OnStartup([CanBeNull] StartupEventArgs e)
    {
      base.OnStartup(e);

      if (CoreApp.IsFirstRun)
      {
        CacheManager.ClearAll();

        Directory.Delete(ApplicationManager.TempFolder, true);

        foreach (var filePath in Directory.GetFiles(".", "*-xml", SearchOption.AllDirectories))
        {
          if (filePath == null)
          {
            continue;
          }

          var newFilePath = filePath.Substring(0, filePath.Length - 4) + ".xml";
          if (File.Exists(newFilePath))
          {
            File.Delete(newFilePath);
          }

          File.Move(filePath, newFilePath);
        }
      }
{'fraction_non_alphanumeric': 0.08797327394209355, 'fraction_numerical': 0.005567928730512249, 'mean_word_length': 2.916424418604651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4193769', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1567, 'n_words': 396}