<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Steamworks.Data;

namespace Steamworks
{
	/// <summary>
	/// Exposes a wide range of information and actions for applications and Downloadable Content (DLC).
	/// </summary>
	public static class SteamApps
	{
		static ISteamApps _internal;
		internal static ISteamApps Internal
		{
			get
			{
				if ( _internal == null )
					_internal = new ISteamApps();

				return _internal;
			}
		}

		internal static void InstallEvents()
		{
			new Event<DlcInstalled_t>( x => OnDlcInstalled?.Invoke( x.AppID ) );
			new Event<NewUrlLaunchParameters_t>( x => OnNewLaunchParameters?.Invoke() );
		}

		/// <summary>
		/// posted after the user gains ownership of DLC and that DLC is installed
		/// </summary>
		public static event Action< AppId > OnDlcInstalled;

		/// <summary>
		/// posted after the user gains executes a Steam URL with command line or query parameters
		/// such as steam://run/appid//-commandline/?param1=value1(and)param2=value2(and)param3=value3 etc
		/// while the game is already running.  The new params can be queried
		/// with GetLaunchQueryParam and GetLaunchCommandLine
		/// </summary>
		public static event Action OnNewLaunchParameters;

		/// <summary>
		/// Checks if the active user is subscribed to the current App ID
		/// </summary>
		public static bool IsSubscribed => Internal.BIsSubscribed();

		/// <summary>
		/// Check if user borrowed this game via Family Sharing, If true, call GetAppOwner() to get the lender SteamID
		/// </summary>
		public static bool IsSubscribedFromFamilySharing => Internal.BIsSubscribedFromFamilySharing();

		/// <summary>
		/// Checks if the license owned by the user provides low violence depots.
		/// Low violence depots are useful for copies sold in countries that have content restrictions
		/// </summary>
		public static bool IsLowVoilence => Internal.BIsLowViolence();

		/// <summary>
		/// Checks whether the current App ID license is for Cyber Cafes.
		/// </summary>
		public static bool IsCybercafe => Internal.BIsCybercafe();

		/// <summary>
		/// CChecks if the user has a VAC ban on their account
		/// </summary>
		public static bool IsVACBanned => Internal.BIsVACBanned();

		/// <summary>
		/// Gets the current language that the user has set.
		/// This falls back to the Steam UI language if the user hasn't explicitly picked a language for the title.
		/// </summary>
		public static string GameLanguage => Internal.GetCurrentGameLanguage();

		/// <summary>
		/// Gets a list of the languages the current app supports.
		/// </summary>
		public static string[] AvailablLanguages => Internal.GetAvailableGameLanguages().Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries );

		/// <summary>
		/// Checks if the active user is subscribed to a specified AppId.
		/// Only use this if you need to check ownership of another game related to yours, a demo for example.
		/// </summary>
		public static bool IsSubscribedToApp( AppId appid ) => Internal.BIsSubscribedApp( appid.Value );

		/// <summary>
		/// Checks if the user owns a specific DLC and if the DLC is installed
		/// </summary>
		public static bool IsDlcInstalled( AppId appid ) => Internal.BIsDlcInstalled( appid.Value );

		/// <summary>
		/// Returns the time of the purchase of the app
		/// </summary>
		public static DateTime PurchaseTime( AppId appid ) => Epoch.ToDateTime( Internal.GetEarliestPurchaseUnixTime( appid.Value ) );

		/// <summary>
		/// Checks if the user is subscribed to the current app through a free weekend
		/// This function will return false for users who have a retail or other type of license
		/// Before using, please ask your Valve technical contact how to package and secure your free weekened
		/// </summary>
		public static bool IsSubscribedFromFreeWeekend => Internal.BIsSubscribedFromFreeWeekend();

		/// <summary>
		/// Returns metadata for all available DLC
		/// </summary>
		public static IEnumerable<DlcInformation> DlcInformation()
		{
			var appid = default( AppId );
			var available = false;

			for ( int i = 0; i < Internal.GetDLCCount(); i++ )
			{
				var sb = Helpers.TakeStringBuilder();

				if ( !Internal.BGetDLCDataByIndex( i, ref appid, ref available, sb, sb.Capacity ) )
					continue;

				yield return new DlcInformation
				{
					AppId = appid.Value,
					Name = sb.ToString(),
					Available = available
				};
			}
		}

		/// <summary>
		/// Install/Uninstall control for optional DLC
		/// </summary>
		public static void InstallDlc( AppId appid ) => Internal.InstallDLC( appid.Value );

		/// <summary>
		/// Install/Uninstall control for optional DLC
		/// </summary>
		public static void UninstallDlc( AppId appid ) => Internal.UninstallDLC( appid.Value );

		/// <summary>
		/// Returns null if we're not on a beta branch, else the name of the branch
		/// </summary>
		public static string CurrentBetaName
		{
			get
			{
				var sb = Helpers.TakeStringBuilder();

				if ( !Internal.GetCurrentBetaName( sb, sb.Capacity ) )
					return null;

				return sb.ToString();
			}
		}

		/// <summary>
		/// Allows you to force verify game content on next launch.
		///
		/// If you detect the game is out-of-date(for example, by having the client detect a version mismatch with a server),
		/// you can call use MarkContentCorrupt to force a verify, show a message to the user, and then quit.
		/// </summary>
		public static void MarkContentCorrupt( bool missingFilesOnly ) => Internal.MarkContentCorrupt( missingFilesOnly );

		/// <summary>
		/// Gets a list of all installed depots for a given App ID in mount order
		/// </summary>
		public static IEnumerable<DepotId> InstalledDepots( AppId appid )
		{
			var depots = new DepotId_t[32];
			uint count = 0;

			count = Internal.GetInstalledDepots( appid.Value, depots, (uint) depots.Length );

			for ( int i = 0; i < count; i++ )
			{
				yield return new DepotId { Value = depots[i].Value };
			}
		}

		/// <summary>
		/// Gets the install folder for a specific AppID.
		/// This works even if the application is not installed, based on where the game would be installed with the default Steam library location.
		/// </summary>
		public static string AppInstallDir( AppId appid )
		{
			var sb = Helpers.TakeStringBuilder();

			if ( Internal.GetAppInstallDir( appid.Value, sb, (uint) sb.Capacity ) == 0 )
				return null;

			return sb.ToString();
		}<commit_msg>InstalledDepots, AppInstallDir appd param default to current app<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Steamworks.Data;

namespace Steamworks
{
	/// <summary>
	/// Exposes a wide range of information and actions for applications and Downloadable Content (DLC).
	/// </summary>
	public static class SteamApps
	{
		static ISteamApps _internal;
		internal static ISteamApps Internal
		{
			get
			{
				if ( _internal == null )
					_internal = new ISteamApps();

				return _internal;
			}
		}

		internal static void InstallEvents()
		{
			new Event<DlcInstalled_t>( x => OnDlcInstalled?.Invoke( x.AppID ) );
			new Event<NewUrlLaunchParameters_t>( x => OnNewLaunchParameters?.Invoke() );
		}

		/// <summary>
		/// posted after the user gains ownership of DLC and that DLC is installed
		/// </summary>
		public static event Action< AppId > OnDlcInstalled;

		/// <summary>
		/// posted after the user gains executes a Steam URL with command line or query parameters
		/// such as steam://run/appid//-commandline/?param1=value1(and)param2=value2(and)param3=value3 etc
		/// while the game is already running.  The new params can be queried
		/// with GetLaunchQueryParam and GetLaunchCommandLine
		/// </summary>
		public static event Action OnNewLaunchParameters;

		/// <summary>
		/// Checks if the active user is subscribed to the current App ID
		/// </summary>
		public static bool IsSubscribed => Internal.BIsSubscribed();

		/// <summary>
		/// Check if user borrowed this game via Family Sharing, If true, call GetAppOwner() to get the lender SteamID
		/// </summary>
		public static bool IsSubscribedFromFamilySharing => Internal.BIsSubscribedFromFamilySharing();

		/// <summary>
		/// Checks if the license owned by the user provides low violence depots.
		/// Low violence depots are useful for copies sold in countries that have content restrictions
		/// </summary>
		public static bool IsLowVoilence => Internal.BIsLowViolence();

		/// <summary>
		/// Checks whether the current App ID license is for Cyber Cafes.
		/// </summary>
		public static bool IsCybercafe => Internal.BIsCybercafe();

		/// <summary>
		/// CChecks if the user has a VAC ban on their account
		/// </summary>
		public static bool IsVACBanned => Internal.BIsVACBanned();

		/// <summary>
		/// Gets the current language that the user has set.
		/// This falls back to the Steam UI language if the user hasn't explicitly picked a language for the title.
		/// </summary>
		public static string GameLanguage => Internal.GetCurrentGameLanguage();

		/// <summary>
		/// Gets a list of the languages the current app supports.
		/// </summary>
		public static string[] AvailablLanguages => Internal.GetAvailableGameLanguages().Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries );

		/// <summary>
		/// Checks if the active user is subscribed to a specified AppId.
		/// Only use this if you need to check ownership of another game related to yours, a demo for example.
		/// </summary>
		public static bool IsSubscribedToApp( AppId appid ) => Internal.BIsSubscribedApp( appid.Value );

		/// <summary>
		/// Checks if the user owns a specific DLC and if the DLC is installed
		/// </summary>
		public static bool IsDlcInstalled( AppId appid ) => Internal.BIsDlcInstalled( appid.Value );

		/// <summary>
		/// Returns the time of the purchase of the app
		/// </summary>
		public static DateTime PurchaseTime( AppId appid ) => Epoch.ToDateTime( Internal.GetEarliestPurchaseUnixTime( appid.Value ) );

		/// <summary>
		/// Checks if the user is subscribed to the current app through a free weekend
		/// This function will return false for users who have a retail or other type of license
		/// Before using, please ask your Valve technical contact how to package and secure your free weekened
		/// </summary>
		public static bool IsSubscribedFromFreeWeekend => Internal.BIsSubscribedFromFreeWeekend();

		/// <summary>
		/// Returns metadata for all available DLC
		/// </summary>
		public static IEnumerable<DlcInformation> DlcInformation()
		{
			var appid = default( AppId );
			var available = false;

			for ( int i = 0; i < Internal.GetDLCCount(); i++ )
			{
				var sb = Helpers.TakeStringBuilder();

				if ( !Internal.BGetDLCDataByIndex( i, ref appid, ref available, sb, sb.Capacity ) )
					continue;

				yield return new DlcInformation
				{
					AppId = appid.Value,
					Name = sb.ToString(),
					Available = available
				};
			}
		}

		/// <summary>
		/// Install/Uninstall control for optional DLC
		/// </summary>
		public static void InstallDlc( AppId appid ) => Internal.InstallDLC( appid.Value );

		/// <summary>
		/// Install/Uninstall control for optional DLC
		/// </summary>
		public static void UninstallDlc( AppId appid ) => Internal.UninstallDLC( appid.Value );

		/// <summary>
		/// Returns null if we're not on a beta branch, else the name of the branch
		/// </summary>
		public static string CurrentBetaName
		{
			get
			{
				var sb = Helpers.TakeStringBuilder();

				if ( !Internal.GetCurrentBetaName( sb, sb.Capacity ) )
					return null;

				return sb.ToString();
			}
		}

		/// <summary>
		/// Allows you to force verify game content on next launch.
		///
		/// If you detect the game is out-of-date(for example, by having the client detect a version mismatch with a server),
		/// you can call use MarkContentCorrupt to force a verify, show a message to the user, and then quit.
		/// </summary>
		public static void MarkContentCorrupt( bool missingFilesOnly ) => Internal.MarkContentCorrupt( missingFilesOnly );

		/// <summary>
		/// Gets a list of all installed depots for a given App ID in mount order
		/// </summary>
		public static IEnumerable<DepotId> InstalledDepots( AppId appid = default )
		{
			if ( appid == 0 )
				appid = SteamClient.AppId;

			var depots = new DepotId_t[32];
			uint count = 0;

			count = Internal.GetInstalledDepots( appid.Value, depots, (uint) depots.Length );

			for ( int i = 0; i < count; i++ )
			{
				yield return new DepotId { Value = depots[i].Value };
			}
		}

		/// <summary>
		/// Gets the install folder for a specific AppID.
		/// This works even if the application is not installed, based on where the game would be installed with the default Steam library location.
		/// </summary>
		public static string AppInstallDir( AppId appid = default )
		{
			if ( appid == 0 )
				appid = SteamClient.AppId;

			var sb = Helpers.TakeStringBuilder();

			if ( Internal.GetAppInstallDir( appid.Value, sb, (uint) sb.Capacity ) == 0 )
				return null;

			return sb.ToString();
		}
{'fraction_non_alphanumeric': 0.10847380754403205, 'fraction_numerical': 0.001965379091390128, 'mean_word_length': 3.080814312152992, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2955054', 'n_tokens_mistral': 4305, 'n_tokens_neox': 3773, 'n_words': 1425}