public void InvokeCommand(IntPtr pici)
        {
            try
            {
                CMINVOKECOMMANDINFO ici = (CMINVOKECOMMANDINFO)Marshal.PtrToStructure(
                    pici, typeof(CMINVOKECOMMANDINFO));

                int cmd = (ici.verb.ToInt32()) & 0xffff;

                switch (cmd)
                {
                case (int)CommandType.PlayFiles:
                case (int)CommandType.EnqueueFiles:
                    RemoteControlHelper.SendPlayerCommand((CommandType)cmd, fileList.ToArray());
                    break;

                default:
                    Marshal.ThrowExceptionForHR(WinError.E_FAIL);
                    break;
                }
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex, false);
            }
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                if (!ProcessCommandLine(true))
                {
                    try
                    {
                        RemoteControllableApplication.Start(ProTONEConstants.PlayerName);

                        ProcessCommandLine(false);

                        Translator.SetInterfaceLanguage(AppConfig.LanguageID);
                        Translator.RegisterTranslationAssembly(typeof(MediaPlayer).Assembly);
                        Translator.RegisterTranslationAssembly(typeof(MainForm).Assembly);

                        ShortcutMapper.IsPlayer = true;

                        mainFrm = new MainForm();

                        foreach (BasicCommand cmd in _commandQueue)
                        {
                            mainFrm.EnqueueCommand(cmd);
                        }

                        Application.Run(mainFrm);
                        mainFrm.Dispose();


                        ShortcutMapper.Save();
                    }
                    catch (MultipleInstancesException ex)
                    {
                        Logger.LogWarning(ex.Message);

                        // Send an activate command to the main instance
                        RemoteControlHelper.SendPlayerCommand(CommandType.Activate, null);
                    }
                    catch (Exception ex)
                    {
                        ErrorDispatcher.DispatchFatalError(ex);
                    }
                    finally
                    {
                        RemoteControllableApplication.Stop();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchFatalError(ex);
            }
        }
        public static bool ProcessCommandLine(bool testForShellExec)
        {
            string[] cmdLineArgs = Environment.GetCommandLineArgs();

            if (testForShellExec && cmdLineArgs.Length > 1 && cmdLineArgs[1].ToLowerInvariant() == "launch")
            {
                List <string> files = new List <string>();
                for (int i = 2; i < cmdLineArgs.Length; i++)
                {
                    files.Add(cmdLineArgs[i]);
                }

                try
                {
                    CommandType cmdType = (CommandType)Enum.Parse(typeof(CommandType),
                                                                  ProTONEConfig.ExplorerLaunchType);

                    if (SuiteRegistrationSupport.IsContextMenuHandlerRegistered() &&
                        (cmdType == CommandType.PlayFiles || cmdType == CommandType.EnqueueFiles))
                    {
                        if (RemoteControlHelper.IsPlayerRunning())
                        {
                            // There is another player instance that is running.
                            // Just pass the command to that instance and exit.
                            RemoteControlHelper.SendPlayerCommand(cmdType, files.ToArray());
                        }
                        else
                        {
                            // There is no other player instance.
                            // This instance needs to process the command itself.

                            // Note: when player is launched like this - clear previous playlist first.
                            _commandQueue.Add(BasicCommand.Create(CommandType.ClearPlaylist));

                            _commandQueue.Add(BasicCommand.Create(cmdType, files.ToArray()));

                            return(false); // Don't exit
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorDispatcher.DispatchError(ex, false);
                }

                return(true);
            }

            return(false);
        }
 protected override void SendRequestInternal(string request)
 {
     try
     {
         BasicCommand cmd = BasicCommand.Create(request);
         if (cmd != null)
         {
             RemoteControlHelper.SendPlayerCommand(cmd, true);
         }
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
     }
 }
        private async Task Refresh()
        {
            LoadingMessage = "Acquiring control info...";
            IsLoading      = true;

            lastUpdate = DateTime.Now;
            Devices    = new ObservableCollection <IDevice>();

            var devices = await RemoteControlHelper.GetAllDevices();

            var combinedControls = dbHelper.GetCombinedControls();

            foreach (var combinedControl in combinedControls)
            {
                var remoDevice = (from device in devices
                                  where typeof(Device) == device.GetType() && ((Device)device).id == combinedControl.RemoID
                                  select device).FirstOrDefault();
                var hueDevice = (from device in devices
                                 where typeof(Models.Hue.Group) == device.GetType() && ((Models.Hue.Group)device).HueGroup.Id == combinedControl.HueID
                                 select device).FirstOrDefault();

                var room = new CombinedRoom(combinedControl.DeviceName, hueDevice as Models.Hue.Group, remoDevice as Device);

                if (remoDevice != null)
                {
                    devices.Remove(remoDevice);
                }
                if (hueDevice != null)
                {
                    devices.Remove(hueDevice);
                }

                Devices.Add(room);
            }

            if (!SettingsHelper.Settings.ShowCombinedRoomOnly.GetValue <bool>())
            {
                foreach (var device in devices)
                {
                    Devices.Add(device);
                }
            }

            IsLoading = false;
        }
        public async void Init()
        {
            IsLoading      = true;
            LoadingMessage = "Retrieving control info...";
            try
            {
                var remoTask = RemoteControlHelper.GetRemoDevices();
                var hueTask  = RemoteControlHelper.GetHueDevices();
                await dbHelper.Init();

                RemoDevices      = new ObservableCollection <IDevice>(await remoTask);
                HueDevices       = new ObservableCollection <IDevice>(await hueTask);
                CombinedControls = dbHelper.GetCombinedControls();

                // filter out in use devices
                var usedRemoIDs = from control in CombinedControls
                                  where !string.IsNullOrEmpty(control.RemoID)
                                  select control.RemoID;
                var usedRemoDevices = (from device in RemoDevices
                                       where usedRemoIDs.Contains(((Models.NatureRemo.Device)device).id)
                                       select device).ToList();
                foreach (var usedRemoDevice in usedRemoDevices)
                {
                    RemoDevices.Remove(usedRemoDevice);
                }

                var usedHueIDs = from control in CombinedControls
                                 where !string.IsNullOrEmpty(control.HueID)
                                 select control.HueID;
                var usedHueDevices = (from device in HueDevices
                                      where usedHueIDs.Contains(((Models.Hue.Group)device).HueGroup.Id)
                                      select device).ToList();
                foreach (var usedHueDevice in usedHueDevices)
                {
                    HueDevices.Remove(usedHueDevice);
                }
            }
            catch (Exception ex)
            {
                DebugHelper.Debugger.WriteErrorLog("Error occurred while retrieving remote control info.", ex);
                await new MessageDialog("Error occurred while retrieving remote control info: " + ex.Message).ShowAsync();
            }
            IsLoading = false;
        }
        private void btnExecute_Click(object sender, EventArgs e)
        {
            txtResult.Text = string.Empty;

            try
            {
                RC.CommandType cmdType = (RC.CommandType)cmbCommandType.SelectedIndex;
                string[]       args    = null;

                if (BasicCommand.RequiresArguments(cmdType))
                {
                    switch (cmdType)
                    {
                    case RC.CommandType.Playback:
                        args = new string[] { cmbPlaybackCmd.Text };
                        break;
                    }
                }

                string restlt = string.Empty;

                switch (cmbDestination.SelectedIndex)
                {
                case 0:
                    RemoteControlHelper.SendPlayerCommand(cmdType, args);
                    txtResult.Text = "[ Player commands do not return results. ]";
                    break;

                case 1:
                    string dest = txtDestinationName.Text;
                    txtResult.Text = RemoteControlHelper.SendServiceCommand(dest, cmdType, args);
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                txtResult.Text = ex.Message;
            }
        }
Example #8
0
        private void RunProTONEActionOnVPaths(List <string> vpaths,
                                              OPMedia.Runtime.ProTONE.RemoteControl.CommandType commandType)
        {
            List <string> launchPaths = new List <string>();

            foreach (string vPath in vpaths)
            {
                CatalogItem ci         = _cat.GetByVPath(vPath);
                string      launchPath = BuildLaunchPath(ci, false);
                if (!string.IsNullOrEmpty(launchPath))
                {
                    launchPaths.Add(launchPath);
                }
            }

            _prevSerialNumber = string.Empty;
            _prevDriveLetter  = string.Empty;

            if (launchPaths.Count > 0)
            {
                RemoteControlHelper.SendPlayerCommand(commandType, launchPaths.ToArray());
            }
        }
Example #9
0
        private void HandleAction(ToolAction action)
        {
            try
            {
                if (!IsToolActionEnabled(action))
                {
                    return;
                }

                FileTaskForm activeFileTask = null;

                updateUiTimer.Stop();

                List <string> selItems = opmShellList.SelectedPaths;
                switch (action)
                {
                case ToolAction.ToolActionNewFolder:
                    opmShellList.CreateNewFolder();
                    return;

                case ToolAction.ToolActionBack:
                    opmShellList.ExploreBack();
                    return;

                case ToolAction.ToolActionFwd:
                    opmShellList.ExploreForward();
                    return;

                case ToolAction.ToolActionUp:
                    NavigateUp();
                    return;

                case ToolAction.ToolActionSearch:
                    SearchWizard.Tasks.Task taskSearch = new SearchWizard.Tasks.Task();
                    taskSearch.SearchPath = opmShellList.Path;
                    if (SearchWizardMain.Execute(taskSearch) == DialogResult.OK)
                    {
                        switch (taskSearch.Action)
                        {
                        case ToolAction.ToolActionProTONEEnqueue:
                        {
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                RemoteControlHelper.SendPlayerCommand(
                                    OPMedia.Runtime.ProTONE.RemoteControl.CommandType.EnqueueFiles,
                                    taskSearch.MatchingItems.ToArray());
                            }
                        }
                        break;

                        case ToolAction.ToolActionProTONEPlay:
                        {
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                RemoteControlHelper.SendPlayerCommand(
                                    OPMedia.Runtime.ProTONE.RemoteControl.CommandType.PlayFiles,
                                    taskSearch.MatchingItems.ToArray());
                            }
                        }
                        break;

                        case ToolAction.ToolActionJumpToItem:
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                opmShellList.JumpToItem(taskSearch.MatchingItems[0], false);
                            }
                            break;

                        case ToolAction.ToolActionTaggingWizard:
                        {
                            TaggedFileProp.TaggingWizard.Task taskTagging = new TaggedFileProp.TaggingWizard.Task();
                            foreach (string item in taskSearch.MatchingItems)
                            {
                                if (Directory.Exists(item))
                                {
                                    taskTagging.Files.AddRange(PathUtils.EnumFiles(item, "*.mp?", SearchOption.AllDirectories));
                                }
                                else if (File.Exists(item))
                                {
                                    taskTagging.Files.Add(item);
                                }
                            }

                            TaggingWizardMain.Execute(FindForm(), taskTagging);
                            ReloadProperties();
                        }
                        break;

                        case ToolAction.ToolActionCopy:
                            _pasteFileTask = new FEFileTaskForm(FileTaskType.Copy, taskSearch.MatchingItems, opmShellList.Path);
                            break;

                        case ToolAction.ToolActionCut:
                            _pasteFileTask = new FEFileTaskForm(FileTaskType.Move, taskSearch.MatchingItems, opmShellList.Path);
                            break;

                        case ToolAction.ToolActionDelete:
                            _deleteFileTask = new FEFileTaskForm(FileTaskType.Delete, taskSearch.MatchingItems, opmShellList.Path);
                            activeFileTask  = _deleteFileTask;
                            break;

                        case ToolAction.ToolActionLaunch:
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                opmShellList.OpenItem(taskSearch.MatchingItems[0]);
                            }
                            break;
                        }
                    }
                    return;

                case ToolAction.ToolActionReload:
                    GlobalReload();
                    return;

                case ToolAction.ToolActionTaggingWizard:
                {
                    TaggedFileProp.TaggingWizard.Task taskTagging = new TaggedFileProp.TaggingWizard.Task();
                    foreach (string item in opmShellList.SelectedPaths)
                    {
                        if (Directory.Exists(item))
                        {
                            taskTagging.Files.AddRange(PathUtils.EnumFiles(item, "*.mp?", SearchOption.AllDirectories));
                        }
                        else if (File.Exists(item))
                        {
                            taskTagging.Files.Add(item);
                        }
                    }

                    TaggingWizardMain.Execute(FindForm(), taskTagging);

                    if (taskTagging.TaskType != TaskType.MultiRename)
                    {
                        ReloadProperties();
                    }
                    else
                    {
                        RaiseNavigationAction(NavActionType.ActionSelectMultipleItems, opmShellList.SelectedPaths);
                    }
                }
                    return;

                case ToolAction.ToolActionCdRipper:
                {
                    OPMedia.Addons.Builtin.Navigation.FileExplorer.CdRipperWizard.Tasks.Task task =
                        new Navigation.FileExplorer.CdRipperWizard.Tasks.Task();

                    task.OutputFolder = opmShellList.Path;

                    CdRipperWizardMain.Execute(task);
                    ReloadNavigation();
                }
                break;

                case ToolAction.ToolActionCopy:
                    _pasteFileTask = new FEFileTaskForm(FileTaskType.Copy, opmShellList.SelectedPaths, opmShellList.Path);
                    return;

                case ToolAction.ToolActionCut:
                    _pasteFileTask = new FEFileTaskForm(FileTaskType.Move, opmShellList.SelectedPaths, opmShellList.Path);
                    return;

                case ToolAction.ToolActionPaste:
                    if (_pasteFileTask != null)
                    {
                        _pasteFileTask.DestFolder = opmShellList.Path;
                        activeFileTask            = _pasteFileTask;
                    }
                    break;

                case ToolAction.ToolActionDelete:
                    if (!opmShellList.IsInEditMode)
                    {
                        _deleteFileTask = new FEFileTaskForm(FileTaskType.Delete, opmShellList.SelectedPaths, opmShellList.Path);
                        activeFileTask  = _deleteFileTask;
                    }
                    break;

                case ToolAction.ToolActionRename:
                    Rename();
                    return;

                case ToolAction.ToolActionFavoritesAdd:
                {
                    List <string> favorites = new List <string>(ProTONEConfig.GetFavoriteFolders("FavoriteFolders"));
                    if (favorites.Contains(opmShellList.Path))
                    {
                        return;
                    }

                    favorites.Add(opmShellList.Path);
                    ProTONEConfig.SetFavoriteFolders(favorites, "FavoriteFolders");
                }
                    return;

                case ToolAction.ToolActionFavoritesManage:
                    new FavoriteFoldersManager("FavoriteFolders").ShowDialog();
                    return;

                case ToolAction.ToolActionProTONEEnqueue:
                {
                    List <String> items = opmShellList.SelectedPaths;
                    if (items.Count > 0)
                    {
                        RemoteControlHelper.SendPlayerCommand(
                            OPMedia.Runtime.ProTONE.RemoteControl.CommandType.EnqueueFiles,
                            items.ToArray());
                    }
                }
                break;

                case ToolAction.ToolActionProTONEPlay:
                {
                    List <String> items = opmShellList.SelectedPaths;
                    if (items.Count > 0)
                    {
                        RemoteControlHelper.SendPlayerCommand(
                            OPMedia.Runtime.ProTONE.RemoteControl.CommandType.PlayFiles,
                            items.ToArray());
                    }
                }
                break;
                }

                if (activeFileTask != null)
                {
                    RaiseNavigationAction(NavActionType.ActionCancelAutoPreview, null, null);

                    try
                    {
                        opmShellList.EnableAutoRefresh(false);
                        DialogResult dlg = activeFileTask.ShowDialog();
                    }
                    finally
                    {
                        if (activeFileTask.RequiresRefresh)
                        {
                            opmShellList.RefreshList(true);
                        }

                        opmShellList.EnableAutoRefresh(true);

                        if (activeFileTask.FileTaskType == FileTaskType.Delete)
                        {
                            _deleteFileTask = null;
                        }
                        else
                        {
                            _pasteFileTask = null;
                        }

                        activeFileTask = null;
                    }
                }
            }
            finally
            {
                updateUiTimer.Start();
            }
        }