public void TestCustomDirectory()
        {
            using (HeadlessGameHost host = new TestRunHeadlessGameHost(nameof(TestCustomDirectory), null)) // don't use clean run as we are writing a config file.
            {
                string       osuDesktopStorage = Path.Combine(host.UserStoragePaths.First(), nameof(TestCustomDirectory));
                const string custom_tournament = "custom";

                // need access before the game has constructed its own storage yet.
                Storage storage = new DesktopStorage(osuDesktopStorage, host);
                // manual cleaning so we can prepare a config file.
                storage.DeleteDirectory(string.Empty);

                using (var storageConfig = new TournamentStorageManager(storage))
                    storageConfig.SetValue(StorageConfig.CurrentTournament, custom_tournament);

                try
                {
                    var osu = LoadTournament(host);

                    storage = osu.Dependencies.Get <Storage>();

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(Path.Combine(host.Storage.GetFullPath("."), "tournaments", custom_tournament)));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Exemple #2
0
        public void TestCustomDirectory()
        {
            using (var host = new HeadlessGameHost(nameof(TestCustomDirectory)))
            {
                string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestCustomDirectory));

                // need access before the game has constructed its own storage yet.
                Storage storage = new DesktopStorage(defaultStorageLocation, host);
                // manual cleaning so we can prepare a config file.
                storage.DeleteDirectory(string.Empty);

                using (var storageConfig = new StorageConfigManager(storage))
                    storageConfig.Set(StorageConfig.FullPath, customPath);

                try
                {
                    var osu = loadOsu(host);

                    // switch to DI'd storage
                    storage = osu.Dependencies.Get <Storage>();

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Exemple #3
0
 public void Unload(DesktopStorage storage)
 {
     using (var file = new StreamWriter(storage.GetStream("Generic Commans.json", FileAccess.Write, FileMode.Truncate)))
     {
         file.Flush();
         file.Write(JsonConvert.SerializeObject(CommandsListBox.Items));
     }
 }
Exemple #4
0
        public void TestRelativePaths()
        {
            var guid    = new Guid().ToString();
            var storage = new DesktopStorage(guid, null);

            var basePath = storage.GetFullPath(string.Empty);

            Assert.IsTrue(basePath.EndsWith(guid));

            Assert.Throws <ArgumentException>(() => storage.GetFullPath("../"));
            Assert.Throws <ArgumentException>(() => storage.GetFullPath(".."));
            Assert.Throws <ArgumentException>(() => storage.GetFullPath("./../"));

            Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")) + Path.DirectorySeparatorChar, storage.GetFullPath("sub/test/"));
            Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")), storage.GetFullPath("sub/test"));

            storage.DeleteDirectory(string.Empty);
        }
Exemple #5
0
 public new void Load(DesktopStorage storage)
 {
     using (var stream = storage.GetStream("Generic Commans.json", FileAccess.ReadWrite, FileMode.OpenOrCreate))
     {
         using (var file = new StreamReader(stream))
         {
             try
             {
                 var l = new ListBox.ObjectCollection(CommandsListBox, JsonConvert.DeserializeObject <string[]>(file.ReadToEnd()));
                 CommandsListBox.Items.AddRange(l);
             }
             catch (System.ArgumentNullException e)
             {
                 Logger.Log("Can't reand data from config for generic commands. Removing the file...");
                 storage.Delete("Generic Commans.json");
             }
         }
     }
 }
        protected override void OnModuleBuilding(CommandService commandService, ModuleBuilder builder)
        {
            base.OnModuleBuilding(commandService, builder);

            Config = new DustConfig(Storage = (DesktopStorage)BotEntry.Storage.GetStorageForDirectory("Dust"));
            Config.Load();

            Colldown    = Config.GetBindable <int>(DustConfigEnum.GainTime);
            SubMultiply = Config.GetBindable <int>(DustConfigEnum.SubMul);

            DustRecalculateTime = DateTimeOffset.Now.AddSeconds(Colldown);

            BotEntry.RegisterItem <RedstoneTorch>();
            BotEntry.RegisterItem <Piston>();

            BotEntry.OnTickActions += OnTick;
            BotEntry.OnExiting     += () =>
            {
                Config.Save();
            };
        }
Exemple #7
0
        public void TestSubDirectoryLookup()
        {
            using (var host = new HeadlessGameHost(nameof(TestSubDirectoryLookup)))
            {
                string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestSubDirectoryLookup));

                // need access before the game has constructed its own storage yet.
                Storage storage = new DesktopStorage(defaultStorageLocation, host);
                // manual cleaning so we can prepare a config file.
                storage.DeleteDirectory(string.Empty);

                using (var storageConfig = new StorageConfigManager(storage))
                    storageConfig.Set(StorageConfig.FullPath, customPath);

                try
                {
                    var osu = loadOsu(host);

                    // switch to DI'd storage
                    storage = osu.Dependencies.Get <Storage>();

                    string actualTestFile = Path.Combine(customPath, "rulesets", "test");

                    File.WriteAllText(actualTestFile, "test");

                    var rulesetStorage = storage.GetStorageForDirectory("rulesets");
                    var lookupPath     = rulesetStorage.GetFiles(".").Single();

                    Assert.That(lookupPath, Is.EqualTo("test"));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Exemple #8
0
        private Storage initialiseIPCStorage(string path)
        {
            scheduled?.Cancel();

            IPCStorage = null;

            try
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(null);
                }

                IPCStorage = new DesktopStorage(path, host as DesktopGameHost);

                const string file_ipc_filename         = "ipc.txt";
                const string file_ipc_state_filename   = "ipc-state.txt";
                const string file_ipc_scores_filename  = "ipc-scores.txt";
                const string file_ipc_channel_filename = "ipc-channel.txt";

                if (IPCStorage.Exists(file_ipc_filename))
                {
                    scheduled = Scheduler.AddDelayed(delegate
                    {
                        try
                        {
                            using (var stream = IPCStorage.GetStream(file_ipc_filename))
                                using (var sr = new StreamReader(stream))
                                {
                                    var beatmapId = int.Parse(sr.ReadLine());
                                    var mods      = int.Parse(sr.ReadLine());

                                    if (lastBeatmapId != beatmapId)
                                    {
                                        beatmapLookupRequest?.Cancel();

                                        lastBeatmapId = beatmapId;

                                        var existing = ladder.CurrentMatch.Value?.Round.Value?.Beatmaps.FirstOrDefault(b => b.ID == beatmapId && b.BeatmapInfo != null);

                                        if (existing != null)
                                        {
                                            Beatmap.Value = existing.BeatmapInfo;
                                        }
                                        else
                                        {
                                            beatmapLookupRequest = new GetBeatmapRequest(new BeatmapInfo {
                                                OnlineBeatmapID = beatmapId
                                            });
                                            beatmapLookupRequest.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets);
                                            API.Queue(beatmapLookupRequest);
                                        }
                                    }

                                    Mods.Value = (LegacyMods)mods;
                                }
                        }
                        catch
                        {
                            // file might be in use.
                        }

                        try
                        {
                            using (var stream = IPCStorage.GetStream(file_ipc_channel_filename))
                                using (var sr = new StreamReader(stream))
                                {
                                    ChatChannel.Value = sr.ReadLine();
                                }
                        }
                        catch (Exception)
                        {
                            // file might be in use.
                        }

                        try
                        {
                            using (var stream = IPCStorage.GetStream(file_ipc_state_filename))
                                using (var sr = new StreamReader(stream))
                                {
                                    State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
                                }
                        }
                        catch (Exception)
                        {
                            // file might be in use.
                        }

                        try
                        {
                            using (var stream = IPCStorage.GetStream(file_ipc_scores_filename))
                                using (var sr = new StreamReader(stream))
                                {
                                    Score1.Value = int.Parse(sr.ReadLine());
                                    Score2.Value = int.Parse(sr.ReadLine());
                                }
                        }
                        catch (Exception)
                        {
                            // file might be in use.
                        }
                    }, 250, true);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, "Stable installation could not be found; disabling file based IPC");
            }

            return(IPCStorage);
        }