<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.IO;

namespace osu.Framework.Platform
{
    public abstract class Storage
    {
        protected string BasePath { get; }

        protected Storage(string path, string subfolder = null)
        {
            static string filenameStrip(string entry)
            {
                foreach (char c in Path.GetInvalidFileNameChars())
                    entry = entry.Replace(c.ToString(), string.Empty);
                return entry;
            }

            BasePath = path;

            if (BasePath == null)
                throw new InvalidOperationException($"{nameof(BasePath)} not correctly initialized!");

            if (!string.IsNullOrEmpty(subfolder))
                BasePath = Path.Combine(BasePath, filenameStrip(subfolder));
        }

        /// <summary>
        /// Get a usable filesystem path for the provided incomplete path.
        /// </summary>
        /// <param name="path">An incomplete path, usually provided as user input.</param>
        /// <param name="createIfNotExisting">Create the path if it doesn't already exist.</param>
        /// <returns>A usable filesystem path.</returns>
        public abstract string GetFullPath(string path, bool createIfNotExisting = false);

        /// <summary>
        /// Check whether a file exists at the specified path.
        /// </summary>
        /// <param name="path">The path to check.</param>
        /// <returns>Whether a file exists.</returns>
        public abstract bool Exists(string path);

        /// <summary>
        /// Check whether a directory exists at the specified path.
        /// </summary>
        /// <param name="path">The path to check.</param>
        /// <returns>Whether a directory exists.</returns>
        public abstract bool ExistsDirectory(string path);

        /// <summary>
        /// Delete a directory and all its contents recursively.
        /// </summary>
        /// <param name="path">The path of the directory to delete.</param>
        public abstract void DeleteDirectory(string path);

        /// <summary>
        /// Delete a file.
        /// </summary>
        /// <param name="path">The path of the file to delete.</param>
        public abstract void Delete(string path);

        /// <summary>
        /// Retrieve a list of directories at the specified path.
        /// </summary>
        /// <param name="path">The path to list.</param>
        /// <returns>A list of directories in the path, relative to the path of this storage.</returns>
        public abstract IEnumerable<string> GetDirectories(string path);

        /// <summary>
        /// Retrieve a list of files at the specified path.
        /// </summary>
        /// <param name="path">The path to list.</param>
        /// <param name="pattern">An optional search pattern. Accepts "*" wildcard.</param>
        /// <returns>A list of files in the path, relative to the path of this storage.</returns>
        public abstract IEnumerable<string> GetFiles(string path, string pattern = "*");

        /// <summary>
        /// Retrieve a <see cref="Storage"/> for a contained directory.
        /// Creates the path if not existing.
        /// </summary>
        /// <param name="path">The subdirectory to use as a root.</param>
        /// <returns>A more specific storage.</returns>
        public virtual Storage GetStorageForDirectory(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("Must be non-null and not empty string", nameof(path));

            if (!path.EndsWith(Path.DirectorySeparatorChar))
                path += Path.DirectorySeparatorChar;

            // create non-existing path.
            var fullPath = GetFullPath(path, true);

            return (Storage)Activator.CreateInstance(GetType(), fullPath);
        }

        /// <summary>
        /// Retrieve a stream from an underlying file inside this storage.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <param name="access">The access requirements.</param>
        /// <param name="mode">The mode in which the file should be opened.</param>
        /// <returns>A stream associated with the requested path.</returns>
        public abstract Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate);

        /// <summary>
        /// Requests that a file be opened externally with an associated application, if available.
        /// </summary>
        /// <param name="filename">The relative path to the file which should be opened.</param>
        public abstract void OpenFileExternally(string filename);

        /// <summary>
        /// Opens a native file browser window to the root path of this storage.
        /// </summary>
        public void PresentExternally() => OpenFileExternally(string.Empty);

        /// <summary>
        /// Requests to present a file externally in the platform's native file browser.
        /// </summary>
        /// <remarks>
        /// This will open the parent folder and, (if available) highlight the file.
        /// </remarks>
        /// <param name="filename">Relative path to the file.</param>
        public abstract void PresentFileExternally(string filename);
    }
}<commit_msg>Correct incorrect call for `PresentExternally`<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.IO;

namespace osu.Framework.Platform
{
    public abstract class Storage
    {
        protected string BasePath { get; }

        protected Storage(string path, string subfolder = null)
        {
            static string filenameStrip(string entry)
            {
                foreach (char c in Path.GetInvalidFileNameChars())
                    entry = entry.Replace(c.ToString(), string.Empty);
                return entry;
            }

            BasePath = path;

            if (BasePath == null)
                throw new InvalidOperationException($"{nameof(BasePath)} not correctly initialized!");

            if (!string.IsNullOrEmpty(subfolder))
                BasePath = Path.Combine(BasePath, filenameStrip(subfolder));
        }

        /// <summary>
        /// Get a usable filesystem path for the provided incomplete path.
        /// </summary>
        /// <param name="path">An incomplete path, usually provided as user input.</param>
        /// <param name="createIfNotExisting">Create the path if it doesn't already exist.</param>
        /// <returns>A usable filesystem path.</returns>
        public abstract string GetFullPath(string path, bool createIfNotExisting = false);

        /// <summary>
        /// Check whether a file exists at the specified path.
        /// </summary>
        /// <param name="path">The path to check.</param>
        /// <returns>Whether a file exists.</returns>
        public abstract bool Exists(string path);

        /// <summary>
        /// Check whether a directory exists at the specified path.
        /// </summary>
        /// <param name="path">The path to check.</param>
        /// <returns>Whether a directory exists.</returns>
        public abstract bool ExistsDirectory(string path);

        /// <summary>
        /// Delete a directory and all its contents recursively.
        /// </summary>
        /// <param name="path">The path of the directory to delete.</param>
        public abstract void DeleteDirectory(string path);

        /// <summary>
        /// Delete a file.
        /// </summary>
        /// <param name="path">The path of the file to delete.</param>
        public abstract void Delete(string path);

        /// <summary>
        /// Retrieve a list of directories at the specified path.
        /// </summary>
        /// <param name="path">The path to list.</param>
        /// <returns>A list of directories in the path, relative to the path of this storage.</returns>
        public abstract IEnumerable<string> GetDirectories(string path);

        /// <summary>
        /// Retrieve a list of files at the specified path.
        /// </summary>
        /// <param name="path">The path to list.</param>
        /// <param name="pattern">An optional search pattern. Accepts "*" wildcard.</param>
        /// <returns>A list of files in the path, relative to the path of this storage.</returns>
        public abstract IEnumerable<string> GetFiles(string path, string pattern = "*");

        /// <summary>
        /// Retrieve a <see cref="Storage"/> for a contained directory.
        /// Creates the path if not existing.
        /// </summary>
        /// <param name="path">The subdirectory to use as a root.</param>
        /// <returns>A more specific storage.</returns>
        public virtual Storage GetStorageForDirectory(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("Must be non-null and not empty string", nameof(path));

            if (!path.EndsWith(Path.DirectorySeparatorChar))
                path += Path.DirectorySeparatorChar;

            // create non-existing path.
            var fullPath = GetFullPath(path, true);

            return (Storage)Activator.CreateInstance(GetType(), fullPath);
        }

        /// <summary>
        /// Retrieve a stream from an underlying file inside this storage.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <param name="access">The access requirements.</param>
        /// <param name="mode">The mode in which the file should be opened.</param>
        /// <returns>A stream associated with the requested path.</returns>
        public abstract Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate);

        /// <summary>
        /// Requests that a file be opened externally with an associated application, if available.
        /// </summary>
        /// <param name="filename">The relative path to the file which should be opened.</param>
        public abstract void OpenFileExternally(string filename);

        /// <summary>
        /// Opens a native file browser window to the root path of this storage.
        /// </summary>
        public void PresentExternally() => PresentFileExternally(string.Empty);

        /// <summary>
        /// Requests to present a file externally in the platform's native file browser.
        /// </summary>
        /// <remarks>
        /// This will open the parent folder and, (if available) highlight the file.
        /// </remarks>
        /// <param name="filename">Relative path to the file.</param>
        public abstract void PresentFileExternally(string filename);
    }
}
{'fraction_non_alphanumeric': 0.11819004524886878, 'fraction_numerical': 0.0, 'mean_word_length': 2.089460441710931, 'pattern_counts': {'":': 0, '<': 153, '<?xml version=': 0, '>': 155, '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': '4312067', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2624, 'n_words': 976}