public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientDeletePlaylist;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            var op  = new DeletePlaylistOp(msg.PlaylistID);
            var qae = _getQae();

            op.OpFinished += (s, e) =>
            {
                ActionResponse resp;
                if (e.Status == OpStatus.Complete)
                {
                    _getConfig().Config = qae.GetCurrentConfig();
                    resp = new ActionResponse()
                    {
                        ResponseToMessageID = msg.MessageID, Success = true
                    };
                }
                else
                {
                    resp = new ActionResponse()
                    {
                        ResponseToMessageID = msg.MessageID, Success = false, ErrorMessage = e.Exception?.Message ?? "An error occurred"
                    };
                }
                sendHostMessage(resp);
            };
            qae.OpManager.QueueOp(op);
        }
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            List <AssetOp> opCopy;

            lock (_opList)
            {
                var msg = message as ClientGetOps;
                if (msg.ClearFailedOps)
                {
                    _opList.RemoveAll(x => x.Status == OpStatus.Failed);
                }
                opCopy = _opList.ToList();
            }

            HostOpStatus opstat = new HostOpStatus();

            foreach (var op in opCopy)
            {
                opstat.Ops.Add(new HostOp()
                {
                    ID = op.ID, OpDescription = op.GetType().Name, Status = op.Status, Error = op?.Exception?.Message
                });
            }

            _messageSender(opstat);
        }
Esempio n. 3
0
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientSyncSaber;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            List <FeedSyncStatus>         feedStatus = null;
            EventHandler <FeedSyncStatus> handler    = null;

            handler = new EventHandler <FeedSyncStatus>((s, f) =>
            {
                //rare chance, but rather it not crash.  probably dumb.
                if (feedStatus != null)
                {
                    if (!_getSyncManager().ActiveSyncs.Any(x => feedStatus.Contains(x)))
                    {
                        var ar = new ActionResponse();
                        ar.ResponseToMessageID = msg.MessageID;
                        //well, maybe not success
                        ar.Success = true;
                        sendHostMessage(ar);
                        _getSyncManager().SyncStatusUpdate -= handler;
                    }
                }
            });
            _getSyncManager().SyncStatusUpdate += handler;
            feedStatus = _getSyncManager().Sync(msg.SyncOnlyID);
        }
Esempio n. 4
0
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientDeleteMod;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }

            try
            {
                var qae = _getQae();

                var modDef = qae.ModManager.Mods.FirstOrDefault(x => x.ID == msg.ModID);
                if (modDef == null)
                {
                    throw new ArgumentException("Mod ID does not exist!");
                }

                qae.ModManager.DeleteMod(modDef);
                _getConfig().Config = qae.GetCurrentConfig();
                _sendMessage(new ActionResponse()
                {
                    ResponseToMessageID = msg.MessageID, Success = true
                });
            }
            catch (Exception ex)
            {
                Log.LogErr($"Exception deleting mod id {msg.ModID}", ex);
                _sendMessage(new ActionResponse()
                {
                    ResponseToMessageID = msg.MessageID, Success = false, ErrorMessage = "Failed to delete mod"
                });
            }
        }
Esempio n. 5
0
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientUpdateFeedReader;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            var mgr = _getSyncManager();

            var feedCfg = mgr.SyncConfig.FeedReaders.FirstOrDefault(x => x.ID == msg.ID);

            if (feedCfg == null)
            {
                Log.LogErr($"Got message to update feed config with ID {msg.ID} but it wasn't found in the config!");
                return;
            }

            try
            {
                var typedConfig = msg.FeedConfig.ToObject(feedCfg.GetType());
                int idx         = mgr.SyncConfig.FeedReaders.IndexOf(feedCfg);
                mgr.SyncConfig.FeedReaders.Remove(feedCfg);
                if (idx >= mgr.SyncConfig.FeedReaders.Count)
                {
                    idx--;
                }
                mgr.SyncConfig.FeedReaders.Add(typedConfig as FeedConfig);
                mgr.Save();
            }
            catch (Exception ex)
            {
                Log.LogErr($"Exception deserializing JObject into proper type of {feedCfg.GetType().Name} for ID {msg.ID}", ex);
            }
        }
Esempio n. 6
0
 public PostCommitConfig(BeatSaberModder mod, ShowToastDelegate showToast, SendHostMessageDelegate sendMessage, GetQaeDelegate getQae, GetBeatOnConfigDelegate getConfig, Action triggerConfigChanged)
 {
     _mod                  = mod;
     _showToast            = showToast;
     _sendMessage          = sendMessage;
     _getQae               = getQae;
     _getConfig            = getConfig;
     _triggerConfigChanged = triggerConfigChanged;
 }
 public PostReloadSongFolders(BeatSaberModder mod, QaeConfig qaeConfig, ShowToastDelegate showToast, SendHostMessageDelegate sendMessage, GetQaeDelegate getQae, GetBeatOnConfigDelegate getConfig, Action triggerConfigChanged, SetSuppressConfigChangeMessages setSuppressMsg)
 {
     _mod                  = mod;
     _qaeConfig            = qaeConfig;
     _showToast            = showToast;
     _sendMessage          = sendMessage;
     _getQae               = getQae;
     _getConfig            = getConfig;
     _triggerConfigChanged = triggerConfigChanged;
     _setSuppressMsg       = setSuppressMsg;
 }
 public PostCommitConfig(BeatSaberModder mod, ShowToastDelegate showToast, SendHostMessageDelegate sendMessage, GetQaeDelegate getQae, GetBeatOnConfigDelegate getConfig, Action triggerConfigChanged, Func <bool> canSync, Action killBeatSaber, Func <bool> saveCommittedConfig)
 {
     _mod                  = mod;
     _showToast            = showToast;
     _sendMessage          = sendMessage;
     _getQae               = getQae;
     _getConfig            = getConfig;
     _triggerConfigChanged = triggerConfigChanged;
     _canSync              = canSync;
     _killBeatSaber        = killBeatSaber;
     _saveCommittedConfig  = saveCommittedConfig;
 }
Esempio n. 9
0
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientStopDownloads;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            var dlmgr = _getDownloadManager();

            dlmgr.CancelDownloads(msg.DownloadsToStop);
        }
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientSetBeastSaberUsername;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }

            _getSyncManager().SyncConfig.BeastSaberUsername = msg.BeastSaberUsername;
            //todo: save here?
            _getSyncManager().Save();
        }
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientDeleteSong;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            var op  = new DeleteSongOp(msg.SongID);
            var qae = _getQae();

            op.OpFinished += (s, e) =>
            {
                if (e.Status == OpStatus.Complete)
                {
                    _getConfig().Config = qae.GetCurrentConfig();
                }
            };
            qae.OpManager.QueueOp(op);
        }
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientMovePlaylist;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            var       op = new MovePlaylistOp(msg.PlaylistID, msg.Index);
            Stopwatch sw = new Stopwatch();

            var qae = _getQae();

            op.OpFinished += (s, e) =>
            {
                if (e.Status == OpStatus.Complete)
                {
                    _getConfig().Config = qae.GetCurrentConfig();
                }
            };
            qae.OpManager.QueueOp(op);
        }
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientAutoCreatePlaylists;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            if (msg.MaxPerNamePlaylist.HasValue && msg.MaxPerNamePlaylist.Value < 5)
            {
                throw new Exception("You're insane. less than 5 per playlist?");
            }
            var op  = new AutoCreatePlaylistsOp(msg.SortMode, msg.MaxPerNamePlaylist ?? 50, msg.RemoveEmptyPlaylists);
            var qae = _getQae();

            op.OpFinished += (s, e) =>
            {
                if (e.Status == OpStatus.Complete)
                {
                    _getConfig().Config = qae.GetCurrentConfig();
                }
            };
            qae.OpManager.QueueOp(op);
        }
 public PostModInstallStep3(BeatSaberModder mod, SendHostMessageDelegate sendMessage)
 {
     _mod         = mod;
     _sendMessage = sendMessage;
 }
Esempio n. 15
0
 public ClientDeleteModHandler(GetQaeDelegate getQae, GetBeatOnConfigDelegate getConfig, SendHostMessageDelegate sendMessage)
 {
     _getQae      = getQae;
     _getConfig   = getConfig;
     _sendMessage = sendMessage;
 }
        public void HandleMessage(MessageBase message, SendHostMessageDelegate sendHostMessage)
        {
            var msg = message as ClientSetModStatus;

            if (msg == null)
            {
                throw new ArgumentException("Message is not the right type");
            }
            try
            {
                Log.LogMsg($"ClientSetModStatusHandler got message to set mod ID {msg.ModID} to {msg.Status}");
                var qae = _getQae();
                var mod = qae.ModManager.Mods.FirstOrDefault(x => x.ID == msg.ModID);
                if (mod == null)
                {
                    throw new Exception($"Unable to locate mod ID {msg.ModID} to set its status to {msg.Status}!");
                }
                if (mod.Status == msg.Status)
                {
                    throw new Exception($"Message to set mod status, but mod ID {msg.ModID} is already set to status {msg.Status}!");
                }
                List <AssetOp> ops = null;
                switch (msg.Status)
                {
                case QuestomAssets.Mods.ModStatusType.Installed:
                    ops = qae.ModManager.GetInstallModOps(mod);
                    break;

                case QuestomAssets.Mods.ModStatusType.NotInstalled:
                    ops = qae.ModManager.GetUninstallModOps(mod);
                    break;

                default:
                    Log.LogErr($"Unsupported mod status '{msg.Status}' was set for mod ID {mod.ID}");
                    throw new NotImplementedException();
                }
                Log.LogMsg($"Queueing {ops.Count} ops to set mod id {mod.ID} to status {msg.Status}");
                if (ops.Count < 1)
                {
                    throw new Exception("No ops resulted from setting mod status!");
                    return;
                }
                ops.Last().OpFinished += (s, e) =>
                {
                    _getConfig().Config = qae.GetCurrentConfig();
                    if (e.Status == OpStatus.Complete)
                    {
                        var respMsg = new ActionResponse()
                        {
                            ResponseToMessageID = msg.MessageID, Success = true
                        };
                        Log.LogMsg($"Sending host action success response to original message ID {msg.MessageID} for successfully setting mod ID {mod.ID} to status {msg.Status}.");
                        _sendHostMessage(respMsg);
                    }
                    if (e.Status == OpStatus.Failed)
                    {
                        var respMsg = new ActionResponse()
                        {
                            ResponseToMessageID = msg.MessageID, Success = false, ErrorMessage = e?.Exception?.Message
                        };
                        Log.LogErr($"Sending host action FAILED response to original message ID {msg.MessageID} for failing setting mod ID {mod.ID} to status {msg.Status}.", e?.Exception);
                        _sendHostMessage(respMsg);
                    }
                };
                ops.ForEach(x => qae.OpManager.QueueOp(x));
            }
            catch (Exception ex)
            {
                Log.LogErr($"Exception processing client set mod status handler for mod ID {msg.ModID} with intended status {msg.Status}!", ex);
                var respMsg = new ActionResponse()
                {
                    ResponseToMessageID = msg.MessageID, Success = false, ErrorMessage = $"Failed to set mod id {msg.ModID} to {msg.Status}"
                };
                Log.LogErr($"Sending host action FAILED response to original message ID {msg.MessageID} for successfully setting mod ID {msg.ModID} to status {msg.Status}.", ex);
                _sendHostMessage(respMsg);
            }
        }