Exemplo n.º 1
0
 public LoadingControl()
 {
     _viewModel             = new ViewModel.Loading(this);
     _viewModel.FileLoaded += (l) => FileLoaded?.Invoke(l);
     _viewModel.Canceled   += _viewModel_Canceled;
     InitializeComponent();
 }
Exemplo n.º 2
0
        public void LoadFile(string fileType, string filePath)
        {
            m_LogService.Debug("LoadFile fileType:" + fileType + " filePath:" + filePath);
            if (FilePaths.ContainsKey(fileType))
            {
                FilePaths[fileType] = filePath;
            }
            else
            {
                FilePaths.Add(fileType, filePath);
            }

            IniFile file = new IniFile(filePath);

            if (IniFiles.ContainsKey(fileType))
            {
                IniFiles[fileType] = file;
            }
            else
            {
                IniFiles.Add(fileType, file);
            }

            if (FileLoaded != null)
            {
                FileLoaded.Invoke(this, new SettingChangedEventArgs(fileType, filePath));
            }
        }
Exemplo n.º 3
0
    // Load the resource from a path on the users hard drives.
    private byte DefaultRootedResourceLoad(Utf8String gamePath, ResourceManager *resourceManager,
                                           SeFileDescriptor *fileDescriptor, int priority, bool isSync)
    {
        // Specify that we are loading unpacked files from the drive.
        // We need to copy the actual file path in UTF16 (Windows-Unicode) on two locations,
        // but since we only allow ASCII in the game paths, this is just a matter of upcasting.
        fileDescriptor->FileMode = FileMode.LoadUnpackedResource;

        var fd = stackalloc byte[0x20 + 2 * gamePath.Length + 0x16];

        fileDescriptor->FileDescriptor = fd;
        var fdPtr = ( char * )(fd + 0x21);

        for (var i = 0; i < gamePath.Length; ++i)
        {
            (&fileDescriptor->Utf16FileName)[i] = ( char )gamePath.Path[i];
            fdPtr[i] = ( char )gamePath.Path[i];
        }

        (&fileDescriptor->Utf16FileName)[gamePath.Length] = '\0';
        fdPtr[gamePath.Length] = '\0';

        // Use the SE ReadFile function.
        var ret = ReadFile(resourceManager, fileDescriptor, priority, isSync);

        FileLoaded?.Invoke(gamePath, ret != 0, true);
        return(ret);
    }
Exemplo n.º 4
0
        public static void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(MpvHandle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
                Debug.WriteLine(evt.event_id);

                if (MpvWindowHandle == IntPtr.Zero)
                {
                    MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
                }

                switch (evt.event_id)
                {
                case mpv_event_id.MPV_EVENT_SHUTDOWN:
                    Shutdown?.Invoke();
                    AfterShutdown?.Invoke();
                    return;

                case mpv_event_id.MPV_EVENT_FILE_LOADED:
                    FileLoaded?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                    PlaybackRestart?.Invoke();
                    var s = new Size(GetIntProp("dwidth"), GetIntProp("dheight"));

                    if (VideoSize != s)
                    {
                        VideoSize = s;
                        VideoSizeChanged?.Invoke();
                    }

                    break;

                case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE:
                    if (ClientMessage != null)
                    {
                        var client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
                        ClientMessage?.Invoke(NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args));
                    }

                    break;

                case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                    var eventData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                    if (eventData.format == mpv_format.MPV_FORMAT_FLAG)
                    {
                        foreach (var action in BoolPropChangeActions)
                        {
                            action.Invoke(Marshal.PtrToStructure <int>(eventData.data) == 1);
                        }
                    }

                    break;
                }
            }
        }
Exemplo n.º 5
0
    // Load the resource from an SqPack and trigger the FileLoaded event.
    private byte DefaultResourceLoad(Utf8String path, ResourceManager *resourceManager,
                                     SeFileDescriptor *fileDescriptor, int priority, bool isSync)
    {
        var ret = Penumbra.ResourceLoader.ReadSqPackHook.Original(resourceManager, fileDescriptor, priority, isSync);

        FileLoaded?.Invoke(path, ret != 0, false);
        return(ret);
    }
Exemplo n.º 6
0
        public void LoadFile(string fileName)
        {
            try
            {
                _canceled   = false;
                _file       = File.OpenText(fileName);
                _fileLength = new FileInfo(fileName).Length;
                long fileLength = _file.BaseStream.Length;

                var doubleFormat = new NumberFormatInfo {
                    CurrencyDecimalSeparator = "."
                };

                var    listToReturn = new List <Link>();
                string headers;

                if (!_file.EndOfStream)
                {
                    headers = _file.ReadLine();
                    var headersOrder = ParseHeaders(headers);
                    while (!_file.EndOfStream && !_canceled)
                    {
                        string line     = _file.ReadLine();
                        var    splitted = line.Split(';');
                        listToReturn.Add(new Link
                        {
                            //Использовать абсолютные индексы не очень хорошо, лучше объявить константы,
                            //но, т.к. набор заголовков фиксирован, пока можно оставить так
                            date       = DateTime.Parse(splitted[headersOrder[0]]),
                            objectA    = splitted[headersOrder[1]],
                            typeA      = splitted[headersOrder[2]],
                            objectB    = splitted[headersOrder[3]],
                            typeB      = splitted[headersOrder[4]],
                            direction  = (Direction)Enum.Parse(typeof(Direction), splitted[headersOrder[5]], true),
                            color      = (Color)ColorConverter.ConvertFromString(splitted[headersOrder[6]]),
                            intensity  = int.Parse(splitted[headersOrder[7]]),
                            latitudeA  = double.Parse(splitted[headersOrder[8]], doubleFormat),
                            longitudeA = double.Parse(splitted[headersOrder[9]], doubleFormat),
                            latitudeB  = double.Parse(splitted[headersOrder[10]], doubleFormat),
                            longitudeB = double.Parse(splitted[headersOrder[11]], doubleFormat)
                        });
                        ProgressChanged?.Invoke((double)_file.BaseStream.Position / fileLength);
                    }
                }
                else
                {
                    throw new ArgumentException("Файл пуст");
                }
                if (!_canceled)
                {
                    FileLoaded?.Invoke(listToReturn);
                }
            }
            catch (Exception e)
            {
                Error?.Invoke(e.Message);
            }
        }
Exemplo n.º 7
0
        private void btnButton_Click(object sender, EventArgs e)
        {
            if (FileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            TextDisplay     = Path.GetFileName(FileDialog.FileName);
            DataLoadHandler = () => File.ReadAllBytes(FileDialog.FileName);
            FileLoaded?.Invoke(this, new EventArgs());
        }
Exemplo n.º 8
0
 protected virtual void OnFileLoaded()
 {
     try
     {
         RaisePropertyChanged("Model");
         FileLoaded?.Invoke(this, EventArgs.Empty);
     }
     catch (Exception e)
     {
         MessageBox.Show("Oops.. something goes wrong...\n\n" + e.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 9
0
 public void LoadFromDatabase()
 {
     try
     {
         var db = new ApplicationContext();
         db.Links.Load();
         FileLoaded?.Invoke(db.Links.Local.ToList());
     }
     catch (Exception e)
     {
         Error?.Invoke(e.Message);
     }
 }
Exemplo n.º 10
0
            public void LoadFile(Stream stream)
            {
                BinaryReader reader    = new BinaryReader(stream);
                int          fileCount = reader.ReadInt16();

                for (int i = 0; i < fileCount; i++)
                {
                    //reader.ReadByte()
                    byte lastByte = 0;
                    Contract.Requires(lastByte == 0);
                }
                FileLoaded?.Invoke(this, EventArgs.Empty);
            }
Exemplo n.º 11
0
        private void OnEventFromConnection(JToken json)
        {
            var type = json?["type"]?["value"]?.ToString();

            if (type == "2")
            {
                var url  = json?["url"]?["value"]?.ToString();
                var body = json?["body"]?["value"]?.ToString();
                var code = json?["code"]?["value"]?.ToString();
                FileLoaded?.Invoke(this, new ZuRequestInfo {
                    Url = url, Body = body, Code = code
                });
            }
        }
Exemplo n.º 12
0
        async public void LoadByPatchAsync()
        {
            try
            {
                StreamReader sw = new StreamReader(CurrentPatch, Encoding.UTF8);
                Data = await sw.ReadToEndAsync();

                sw.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            FileLoaded?.Invoke(this, Data);
        }
Exemplo n.º 13
0
        /// <summary>
        ///    load file located at path
        /// </summary>
        public async void LoadFileAsync(string path)
        {
            LoadedFilePath = path;
            FileIsLoaded   = true;
            await Task.Run(async() => {
                //load words
                var assembly     = Assembly.GetExecutingAssembly();
                var resourceName = "LuaConverter.Resources.words.gz";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                {
                    using (var zip = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        using (StreamReader reader = new StreamReader(zip))
                        {
                            string line;
                            while ((line = reader.ReadLine()) != null)
                            {
                                WordsDatabase.Add(line);
                            }
                        }
                    }
                }
                if (File.Exists(path))
                {
                    byte[] loadedFile;
                    using (FileStream file = new FileStream(path, FileMode.Open))
                    {
                        try
                        {
                            loadedFile = new byte[file.Length];
                            file.Read(loadedFile, 0, (int)file.Length);
                            var fileText  = await ByteToString(loadedFile);
                            ItemsDatabase = GetDictionaryFromString(fileText);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            LoadedFilePath = null;
                            FileIsLoaded   = false;
                        }
                    }
                }
            });

            FileLoaded.Invoke();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Обработчик события открытия файла
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var saver = new Saver();

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            try
            {
                var fileLoadedEventArgs = saver.OpenFromFile(openFileDialog.FileName);
                FileLoaded?.Invoke(this, fileLoadedEventArgs);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 15
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            List <String> timeList   = new List <string>();
            FileLoaded    filetoload = new FileLoaded();
            FormatLine    formatLine = new FormatLine();

            timeList = FileLoaded.Initial();

            if (timeList.Any())
            {
                foreach (var time in timeList)
                {
                    lstTime.Items.Add(FormatLine.FormatString(time.ToString()));
                }
            }
            else
            {
                Environment.Exit(1);
            }
        }
Exemplo n.º 16
0
        public void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(MpvHandle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
                Debug.WriteLine(evt.event_id);

                switch (evt.event_id)
                {
                case mpv_event_id.MPV_EVENT_SHUTDOWN:
                    Shutdown?.Invoke();
                    AfterShutdown?.Invoke();
                    return;

                case mpv_event_id.MPV_EVENT_FILE_LOADED:
                    FileLoaded?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                    PlaybackRestart?.Invoke();
                    var s = new Size(GetIntProp("dwidth"), GetIntProp("dheight"));


                    break;

                case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                    var eventData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                    if (eventData.format == mpv_format.MPV_FORMAT_FLAG)
                    {
                        foreach (var action in BoolPropChangeActions)
                        {
                            action.Invoke(Marshal.PtrToStructure <int>(eventData.data) == 1);
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 17
0
        public async Task <MediaStatus> LoadAsync(
            MediaInformation media,
            bool autoPlay        = true,
            double seekedSeconds = 0,
            params int[] activeTrackIds)
        {
            _logger.LogInfo($"{nameof(LoadAsync)}: Trying to load media = {media.ContentId}");
            CurrentContentId = null;
            CancelAndSetListenerToken();

            FileLoading?.Invoke(this, EventArgs.Empty);

            var app = await _receiverChannel.GetApplication(_sender, _connectionChannel, _mediaChannel.Namespace);

            var status = await _mediaChannel.LoadAsync(_sender, app.SessionId, media, autoPlay, activeTrackIds);

            if (status is null)
            {
                LoadFailed?.Invoke(this, EventArgs.Empty);
                _logger.LogWarn($"{nameof(LoadAsync)}: Couldn't load media {media.ContentId}");
                return(null);
            }

            CurrentContentId     = media.ContentId;
            CurrentMediaDuration = media.Duration ?? status?.Media?.Duration ?? 0;
            CurrentVolumeLevel   = status?.Volume?.Level ?? 0;
            IsMuted        = status?.Volume?.IsMuted ?? false;
            ElapsedSeconds = 0;
            _seekedSeconds = seekedSeconds;

            TriggerTimeEvents();
            IsPlaying = true;
            IsPaused  = false;
            ListenForMediaChanges(_listenerToken.Token);
            ListenForReceiverChanges(_listenerToken.Token);

            FileLoaded?.Invoke(this, EventArgs.Empty);
            _logger.LogInfo($"{nameof(LoadAsync)}: Media = {media.ContentId} was loaded. Duration = {CurrentMediaDuration} - SeekSeconds = {_seekedSeconds}");
            return(status);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Occurs when an event is received from MPV.
 /// </summary>
 private void Mpv_EventReceived(object sender, MpvMessageEventArgs e)
 {
     if (e.EventName == "start-file")
     {
         StartFile?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "end-file" && EndFile != null)
     {
         var args = new EndFileEventArgs();
         if (Enum.TryParse(e.Data["reason"], true, out EndReason reason))
         {
             args.Reason = reason;
         }
         else
         {
             args.Reason = EndReason.Unknown;
         }
         EndFile?.Invoke(this, args);
     }
     else if (e.EventName == "file-loaded")
     {
         FileLoaded?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "seek")
     {
         Seek?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "playback-restart")
     {
         PlaybackRestart?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "idle")
     {
         Idle?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "tick")
     {
         Tick?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "shutdown")
     {
         Shutdown?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "log-message" && LogMessage != null)
     {
         var args = new LogMessageEventArgs
         {
             Prefix = e.Data["prefix"] ?? string.Empty,
             Level  = FlagExtensions.ParseMpvFlag <LogLevel>(e.Data["level"]) ?? LogLevel.No,
             Text   = e.Data["text"] ?? string.Empty
         };
         LogMessage?.Invoke(this, args);
     }
     else if (e.EventName == "video-reconfig")
     {
         VideoReconfig?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "audio-reconfig")
     {
         AudioReconfig?.Invoke(this, new EventArgs());
     }
     else if (e.EventName == "property-change" && PropertyChanged != null)
     {
         var args = new PropertyChangedEventArgs()
         {
             Id   = e.Data["id"].Parse <int>() ?? 0,
             Data = e.Data["data"] ?? string.Empty,
             Name = e.Data["name"] ?? string.Empty
         };
         PropertyChanged?.Invoke(this, args);
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Raises the FileLoaded event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void RaiseFileLoaded(ProjectIOFileLoadedEventArgs e)
 {
     FileLoaded.Raise(this, e);
 }
Exemplo n.º 20
0
        public static void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(Handle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));

                if (WindowHandle == IntPtr.Zero)
                {
                    WindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
                }

                // Debug.WriteLine(evt.event_id.ToString());

                try
                {
                    switch (evt.event_id)
                    {
                    case mpv_event_id.MPV_EVENT_SHUTDOWN:
                        if (App.DebugMode)
                        {
                            Trace.WriteLine("before Shutdown.Invoke");
                        }
                        Shutdown?.Invoke();
                        if (App.DebugMode)
                        {
                            Trace.WriteLine("after Shutdown.Invoke");
                        }
                        WriteHistory(null);
                        ShutdownAutoResetEvent.Set();
                        return;

                    case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
                        LogMessage?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_GET_PROPERTY_REPLY:
                        GetPropertyReply?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_SET_PROPERTY_REPLY:
                        SetPropertyReply?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_COMMAND_REPLY:
                        CommandReply?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_START_FILE:
                        StartFile?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_END_FILE:
                        var end_fileData        = (mpv_event_end_file)Marshal.PtrToStructure(evt.data, typeof(mpv_event_end_file));
                        EndFileEventMode reason = (EndFileEventMode)end_fileData.reason;
                        EndFile?.Invoke(reason);
                        break;

                    case mpv_event_id.MPV_EVENT_FILE_LOADED:
                        HideLogo();
                        FileLoaded?.Invoke();
                        WriteHistory(get_property_string("path"));
                        break;

                    case mpv_event_id.MPV_EVENT_TRACKS_CHANGED:
                        TracksChanged?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_TRACK_SWITCHED:
                        TrackSwitched?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_IDLE:
                        Idle?.Invoke();
                        if (get_property_int("playlist-count") == 0)
                        {
                            ShowLogo();
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_PAUSE:
                        Pause?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_UNPAUSE:
                        Unpause?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_TICK:
                        Tick?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_SCRIPT_INPUT_DISPATCH:
                        ScriptInputDispatch?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE:
                        var      client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
                        string[] args = NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args);
                        if (args.Length > 1 && args[0] == "mpv.net")
                        {
                            Command.Execute(args[1], args.Skip(2).ToArray());
                        }
                        else if (args.Length > 0)
                        {
                            ClientMessage?.Invoke(args);
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_VIDEO_RECONFIG:
                        VideoReconfig?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_AUDIO_RECONFIG:
                        AudioReconfig?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_METADATA_UPDATE:
                        MetadataUpdate?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_SEEK:
                        Seek?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                        var propData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                        if (propData.format == mpv_format.MPV_FORMAT_FLAG)
                        {
                            foreach (var i in BoolPropChangeActions)
                            {
                                if (i.Key == propData.name)
                                {
                                    i.Value.Invoke(Marshal.PtrToStructure <int>(propData.data) == 1);
                                }
                            }
                        }

                        if (propData.format == mpv_format.MPV_FORMAT_STRING)
                        {
                            foreach (var i in StringPropChangeActions)
                            {
                                if (i.Key == propData.name)
                                {
                                    i.Value.Invoke(StringFromNativeUtf8(Marshal.PtrToStructure <IntPtr>(propData.data)));
                                }
                            }
                        }

                        if (propData.format == mpv_format.MPV_FORMAT_INT64)
                        {
                            foreach (var i in IntPropChangeActions)
                            {
                                if (i.Key == propData.name)
                                {
                                    i.Value.Invoke(Marshal.PtrToStructure <int>(propData.data));
                                }
                            }
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                        PlaybackRestart?.Invoke();
                        string path = get_property_string("path");
                        if (LastPlaybackRestartFile != path)
                        {
                            Size vidSize = new Size(get_property_int("dwidth"), get_property_int("dheight"));
                            if (vidSize.Width == 0 || vidSize.Height == 0)
                            {
                                vidSize = new Size(1, 1);
                            }
                            if (VideoSize != vidSize)
                            {
                                VideoSize = vidSize;
                                VideoSizeChanged?.Invoke();
                            }
                            VideoSizeAutoResetEvent.Set();
                            Task.Run(new Action(() => ReadMetaData()));
                            LastPlaybackRestartFile = path;
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_CHAPTER_CHANGE:
                        ChapterChange?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_QUEUE_OVERFLOW:
                        QueueOverflow?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_HOOK:
                        Hook?.Invoke();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Msg.ShowException(ex);
                }
            }
        }
Exemplo n.º 21
0
 private void OnFileLoaded(DocumentFileEventArgs e)
 {
     FileLoaded?.Invoke(this, e);
 }
Exemplo n.º 22
0
 public Loading(LoadingControl control)
 {
     _control                 = control;
     _loader                  = new Loader();
     _loader.FileLoaded      += (l) => Application.Current.Dispatcher.Invoke(new Action(() => FileLoaded?.Invoke(l)));
     _loader.ProgressChanged += Loader_ProgressChanged;
     _loader.Error           += (s) => Application.Current.Dispatcher.Invoke(new Action(() => Canceled?.Invoke(s)));
 }
Exemplo n.º 23
0
 private void OnFileLoaded()
 {
     fileListView.Sort();
     FileLoaded?.Invoke(this, new EventArgs());
 }
Exemplo n.º 24
0
Arquivo: mp.cs Projeto: amnek0/mpv.net
        public static void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(MpvHandle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));

                if (MpvWindowHandle == IntPtr.Zero)
                {
                    MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
                }

                //Debug.WriteLine(evt.event_id.ToString());

                switch (evt.event_id)
                {
                case mpv_event_id.MPV_EVENT_SHUTDOWN:
                    Shutdown?.Invoke();
                    AutoResetEvent.Set();
                    return;

                case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
                    LogMessage?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_GET_PROPERTY_REPLY:
                    GetPropertyReply?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_SET_PROPERTY_REPLY:
                    SetPropertyReply?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_COMMAND_REPLY:
                    CommandReply?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_START_FILE:
                    StartFile?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_END_FILE:
                    var end_fileData = (mpv_event_end_file)Marshal.PtrToStructure(evt.data, typeof(mpv_event_end_file));
                    EndFile?.Invoke((EndFileEventMode)end_fileData.reason);
                    break;

                case mpv_event_id.MPV_EVENT_FILE_LOADED:
                    FileLoaded?.Invoke();
                    LoadFolder();
                    break;

                case mpv_event_id.MPV_EVENT_TRACKS_CHANGED:
                    TracksChanged?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_TRACK_SWITCHED:
                    TrackSwitched?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_IDLE:
                    Idle?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_PAUSE:
                    Pause?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_UNPAUSE:
                    Unpause?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_TICK:
                    Tick?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_SCRIPT_INPUT_DISPATCH:
                    ScriptInputDispatch?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE:
                    if (ClientMessage != null)
                    {
                        try
                        {
                            var      client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
                            string[] args = NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args);

                            if (args != null && args.Length > 1 && args[0] == "mpv.net")
                            {
                                bool found = false;

                                foreach (var i in mpvnet.Command.Commands)
                                {
                                    if (args[1] == i.Name)
                                    {
                                        found = true;
                                        i.Action.Invoke(args.Skip(2).ToArray());
                                    }
                                }
                                if (!found)
                                {
                                    List <string> names = mpvnet.Command.Commands.Select((item) => item.Name).ToList();
                                    names.Sort();
                                    MainForm.Instance.ShowMsgBox($"No command '{args[1]}' found. Available commands are:\n\n{string.Join("\n", names)}\n\nHow to bind these commands can be seen in the default input bindings and menu definition located at:\n\nhttps://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt", MessageBoxIcon.Error);
                                }
                            }
                            ClientMessage?.Invoke(args);
                        }
                        catch (Exception ex)
                        {
                            MainForm.Instance.ShowMsgBox(ex.GetType().Name + "\n\n" + ex.ToString(), MessageBoxIcon.Error);
                        }
                    }
                    break;

                case mpv_event_id.MPV_EVENT_VIDEO_RECONFIG:
                    VideoReconfig?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_AUDIO_RECONFIG:
                    AudioReconfig?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_METADATA_UPDATE:
                    MetadataUpdate?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_SEEK:
                    Seek?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                    var event_propertyData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                    if (event_propertyData.format == mpv_format.MPV_FORMAT_FLAG)
                    {
                        foreach (var i in BoolPropChangeActions)
                        {
                            if (i.Key == event_propertyData.name)
                            {
                                i.Value.Invoke(Marshal.PtrToStructure <int>(event_propertyData.data) == 1);
                            }
                        }
                    }
                    break;

                case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                    PlaybackRestart?.Invoke();
                    Size s = new Size(get_property_int("dwidth"), get_property_int("dheight"));

                    if (VideoSize != s && s != Size.Empty)
                    {
                        VideoSize = s;
                        VideoSizeChanged?.Invoke();
                    }
                    break;

                case mpv_event_id.MPV_EVENT_CHAPTER_CHANGE:
                    ChapterChange?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_QUEUE_OVERFLOW:
                    QueueOverflow?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_HOOK:
                    Hook?.Invoke();
                    break;
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Fires the <see cref="FileLoaded"/> event.
 /// </summary>
 protected virtual LoggerLoadedEventArgs OnFileLoaded(LoggerLoadedEventArgs e)
 {
     FileLoaded?.Invoke(this, e);
     return(e);
 }
Exemplo n.º 26
0
 private void OnFileLoaded(string str)
 {
     FileLoaded?.Invoke(this, new StringEventArg(str));
 }