<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using osu.Framework.Extensions;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
using SQLite.Net;

namespace osu.Game.IO
{
    /// <summary>
    /// Handles the Store and retrieval of Files/FileSets to the database backing
    /// </summary>
    public class FileStore : DatabaseBackedStore
    {
        private const string prefix = "files";

        public readonly ResourceStore<byte[]> Store;

        protected override int StoreVersion => 2;

        public FileStore(SQLiteConnection connection, Storage storage) : base(connection, storage)
        {
            Store = new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), prefix);
        }

        protected override Type[] ValidTypes => new[] {
            typeof(FileInfo),
        };

        protected override void Prepare(bool reset = false)
        {
            if (reset)
            {
                try
                {
                    foreach (var f in Query<FileInfo>())
                        Storage.Delete(Path.Combine(prefix, f.StoragePath));
                }
                catch
                {
                    // we don't want to ever crash as a result of a reset operation.
                }

                Connection.DropTable<FileInfo>();
            }

            Connection.CreateTable<FileInfo>();
        }

        protected override void StartupTasks()
        {
            base.StartupTasks();
            deletePending();
        }<commit_msg>Use new storage methods to reset FileStore<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using osu.Framework.Extensions;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
using SQLite.Net;

namespace osu.Game.IO
{
    /// <summary>
    /// Handles the Store and retrieval of Files/FileSets to the database backing
    /// </summary>
    public class FileStore : DatabaseBackedStore
    {
        private const string prefix = "files";

        public readonly ResourceStore<byte[]> Store;

        protected override int StoreVersion => 2;

        public FileStore(SQLiteConnection connection, Storage storage) : base(connection, storage)
        {
            Store = new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), prefix);
        }

        protected override Type[] ValidTypes => new[] {
            typeof(FileInfo),
        };

        protected override void Prepare(bool reset = false)
        {
            if (reset)
            {
                // in earlier versions we stored beatmaps as solid archives, but not any more.
                if (Storage.ExistsDirectory("beatmaps"))
                    Storage.DeleteDirectory("beatmaps");

                if (Storage.ExistsDirectory(prefix))
                    Storage.DeleteDirectory(prefix);

                Connection.DropTable<FileInfo>();
            }

            Connection.CreateTable<FileInfo>();
        }

        protected override void StartupTasks()
        {
            base.StartupTasks();
            deletePending();
        }
{'fraction_non_alphanumeric': 0.0960467706013363, 'fraction_numerical': 0.005011135857461025, 'mean_word_length': 2.0814751286449398, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 24, 'https://': 2, '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': '5142812', 'n_tokens_mistral': 945, 'n_tokens_neox': 890, 'n_words': 249}