示例#1
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));
     }
 }
示例#2
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");
             }
         }
     }
 }
示例#3
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);
        }
示例#4
0
        private void OnTick()
        {
            if (DateTimeOffset.Now > DustRecalculateTime)
            {
                var req = new WebRequest($"https://beta.decapi.me/twitch/uptime/{BotEntry.Channel.Value.Substring(1, BotEntry.Channel.Value.Length - 1)}");
                req.Finished += () =>
                {
                    var vars = req.ResponseString.Split(' ');
                    if (vars.Length >= 3 && vars[2] == "offline")
                    {
                        return;
                    }

                    var lreq = new JsonWebRequest <ChatData>($"https://tmi.twitch.tv/group/user/{BotEntry.Channel.Value.Replace("#", "")}/chatters");

                    lreq.Finished += () =>
                    {
                        foreach (var it in lreq.ResponseObject.chatters.viewers)
                        {
                            if (BotEntry.RedstoneDust.ContainsKey(it))
                            {
                                if (BotEntry.RedstoneDust[it].HasBoost)
                                {
                                    BotEntry.RedstoneDust[it].Dust += 1 * SubMultiply;
                                }
                                else
                                {
                                    BotEntry.RedstoneDust[it].Dust += 1;
                                }
                            }
                            else
                            {
                                BotEntry.RedstoneDust.Add(it, new RedstoneData
                                {
                                    Dust     = 1,
                                    HasBoost = false,
                                });
                            }
                            if (BotEntry.RedstoneDust[it].Chatter)
                            {
                                BotEntry.RedstoneDust[it].Dust   += 1;
                                BotEntry.RedstoneDust[it].Chatter = false;
                            }

                            BotEntry.RedstoneDust[it].PrepareJsonData();
                        }



                        using (var file = new StreamWriter(Storage.GetStream($"{BotEntry.Channel}#RedstoneData.json", FileAccess.ReadWrite, FileMode.Truncate)))
                        {
                            file.Write(JsonConvert.SerializeObject(BotEntry.RedstoneDust, Formatting.Indented));
                        }
                    };

                    lreq.Failed += (e) =>
                    {
                        var ex = e;
                    };

                    lreq.PerformAsync();
                };

                req.PerformAsync();



                DustRecalculateTime = DateTimeOffset.Now.AddSeconds(Colldown);
            }
        }