<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using GitDepend.Configuration;

namespace GitDepend.Visitors
{
	public class RunBuildScriptVisitor : IVisitor
	{
		private static readonly Regex Pattern = new Regex(@"^(?<id>.*?)\.(?<version>(?:\d\.){2,3}\d(?:-.*?)?)$", RegexOptions.Compiled);

		private string CacheDirectory
		{
			get
			{
				var location = Assembly.GetEntryAssembly().Location;
				if (location != null)
				{
					var cacheDir = Path.Combine(location, "cache");
					if (!Directory.Exists(cacheDir))
					{
						try
						{
							Directory.CreateDirectory(cacheDir);
						}
						catch (Exception ex)
						{
							Console.Error.WriteLine(ex.Message);
						}
					}

					return cacheDir;
				}
				return null;
			}
		}

		#region Implementation of IVisitor

		public int ReturnCode { get; set; }
		public int VisitDependency(Dependency dependency)
		{
			string dir;
			string error;
			var config = GitDependFile.LoadFromDir(dependency.Directory, out dir, out error);

			if (config == null)
			{
				return ReturnCodes.GitRepositoryNotFound;
			}

			var info = new ProcessStartInfo(Path.Combine(dependency.Directory, config.Build.Script), config.Build.Arguments)
			{
				WorkingDirectory = dependency.Directory,
				UseShellExecute = false
			};<commit_msg>Fixing a bug in the cache directory calculation<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using GitDepend.Configuration;

namespace GitDepend.Visitors
{
	public class RunBuildScriptVisitor : IVisitor
	{
		private static readonly Regex Pattern = new Regex(@"^(?<id>.*?)\.(?<version>(?:\d\.){2,3}\d(?:-.*?)?)$", RegexOptions.Compiled);

		private string CacheDirectory
		{
			get
			{
				var location = Assembly.GetEntryAssembly().Location;
				var dir = Path.GetDirectoryName(location);

				if (dir == null)
				{
					return null;
				}

				var cacheDir = Path.Combine(dir, "cache");
				if (Directory.Exists(cacheDir))
				{
					return cacheDir;
				}

				try
				{
					Directory.CreateDirectory(cacheDir);
				}
				catch (Exception ex)
				{
					Console.Error.WriteLine(ex.Message);
					return null;
				}

				return cacheDir;
			}
		}

		#region Implementation of IVisitor

		public int ReturnCode { get; set; }
		public int VisitDependency(Dependency dependency)
		{
			string dir;
			string error;
			var config = GitDependFile.LoadFromDir(dependency.Directory, out dir, out error);

			if (config == null)
			{
				return ReturnCodes.GitRepositoryNotFound;
			}

			var info = new ProcessStartInfo(Path.Combine(dependency.Directory, config.Build.Script), config.Build.Arguments)
			{
				WorkingDirectory = dependency.Directory,
				UseShellExecute = false
			};
{'fraction_non_alphanumeric': 0.11471648639790233, 'fraction_numerical': 0.0013110455588331695, 'mean_word_length': 3.4231884057971014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7578362', 'n_tokens_mistral': 1149, 'n_tokens_neox': 900, 'n_words': 212}