Exemplo n.º 1
0
        public static void FireInserted()
        {
            var volumeInfo     = new VolumeInfo();
            var mediaEventArgs = new MediaEventArgs(volumeInfo, DateTime.Now);

            Insert(new object(), mediaEventArgs);
        }
Exemplo n.º 2
0
        private static void MessageHandler(object args)
        {
            try
            {
                StorageEvent ev = args as StorageEvent;

                if (ev == null)
                {
                    return;
                }

                lock (_volumes)
                {
                    if (ev.EventType == StorageEventType.Insert)
                    {
                        VolumeInfo volume = new VolumeInfo(ev.Handle);

                        _volumes.Add(volume);

                        if (Insert != null)
                        {
                            MediaEventArgs mediaEventArgs = new MediaEventArgs(volume, ev.Time);

                            Insert(null, mediaEventArgs);
                        }
                    }
                    else if (ev.EventType == StorageEventType.Eject)
                    {
                        VolumeInfo volumeInfo = RemoveVolume(ev.Handle);

                        if (volumeInfo != null)
                        {
                            FileSystemManager.ForceRemoveNameSpace(volumeInfo.Name);

                            if (Eject != null)
                            {
                                MediaEventArgs mediaEventArgs = new MediaEventArgs(new VolumeInfo(volumeInfo), ev.Time);

                                Eject(null, mediaEventArgs);
                            }
                        }
                    }
                }
            }
            finally
            {
                // get rid of this timer
                _events.Dequeue();
            }
        }
Exemplo n.º 3
0
        private static void MessageHandler(object args)
        {
            StorageEvent ev = args as StorageEvent;

            if (ev == null)
            {
                return;
            }

            if (ev.EventType == StorageEventType.Insert)
            {
                VolumeInfo volume = new VolumeInfo(ev.Handle);

                _volumes.Add(volume);

                if (Insert != null)
                {
                    MediaEventArgs mediaEventArgs = new MediaEventArgs(volume, ev.Time);

                    Insert(null, mediaEventArgs);
                }
            }
            else if (ev.EventType == StorageEventType.Eject)
            {
                VolumeInfo volumeInfo = RemoveVolume(ev.Handle);

                FileSystemManager.ForceRemoveNameSpace(volumeInfo.Name);

                if (Eject != null)
                {
                    MediaEventArgs mediaEventArgs = new MediaEventArgs(new VolumeInfo(volumeInfo), ev.Time);

                    Eject(null, mediaEventArgs);
                }
            }
        }
Exemplo n.º 4
0
        private static void RemovableMedia_Inserted(object sender, MediaEventArgs e)
        {
            // Because of how this is called we have no choice
            // But to assume this is always the last mounted PS

            if (e.Volume.RootDirectory != "\\SD") // USB
            {
                try
                {
                    Drive drive = (Drive)drives[drives.Count - 1];
                    drive.VolumeInfo = e.Volume;
                    drives[drives.Count - 1] = drive;
                }
                catch (Exception) { }
            }
            else
            {
                Drive drive = new Drive()
                {
                    VolumeInfo = e.Volume,
                    Storage = sdCard
                };
                drives.Add(drive);
            }

            // Attempt to get the drive name
            //try
            //{
            //    string sFile = @e.Volume.RootDirectory + "\\volume.info";
            //    if (File.Exists(sFile))
            //    {
            //        Debug.Print("Found volume.info for " + e.Volume.RootDirectory);
            //        byte[] b = new byte[new FileInfo(sFile).Length];
            //        FileStream iFile = new FileStream(sFile, FileMode.Open, FileAccess.Read);
            //        iFile.Read(b, 0, b.Length);
            //        iFile.Close();
            //        Debug.Print(new string(System.Text.UTF8Encoding.UTF8.GetChars(b)));
            //    }
            //}
            //catch (Exception) { }

            if (DriveAdded != null)
                DriveAdded(e.Volume.RootDirectory);
        }
Exemplo n.º 5
0
        private static void RemovableMedia_Ejected(object sender, MediaEventArgs e)
        {
            Drive drive;
            for (int i = 0; i < drives.Count; i++)
            {
                drive = (Drive)drives[i];
                if (drive.VolumeInfo.RootDirectory == e.Volume.RootDirectory)
                {
                    drives.Remove(drive);
                    if (drive.Device != null)
                        drive.Storage.UnmountFileSystem();

                    if (DriveRemoved != null)
                        DriveRemoved(e.Volume.RootDirectory);

                    return;
                }
            }
        }
Exemplo n.º 6
0
 static void Eject(object sender, MediaEventArgs args)
 {
     Debug.Print("Media Ejected: " + args.Volume.Name);
 }
 private void OnRemovableMediaEject(object sender, MediaEventArgs mediaEventArgs)
 {
     Debug.Print("Sd card file system unmounted.");
 }
Exemplo n.º 8
0
        private void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            if (!e.Volume.IsFormatted)
            {
                Logger.WriteInfo("RPTR", "Media is not formatted. Formatting card...");
                Thread.Sleep(5000);
                try
                {
                    sdCard.Mount();
                    Thread.Sleep(2000);

                    e.Volume.Format("FAT", 0, "SD", true);

                    Logger.WriteInfo("RPTR", "Formatting completed");
                }
                catch (Exception ex)
                {
                    Logger.WriteError("RPTR", "Formatting failed ", ex);
                }
            }
            else
            {
                Logger.WriteInfo("RPTR", "Media inserted is formatted with volume: " + e.Volume.Name);
            }
        }
        private static void MessageHandler(object args)
        {
            try
            {
                StorageEvent ev = args as StorageEvent;

                if (ev == null)
                    return;

                lock(_volumes)
                {
                    if (ev.EventType == StorageEventType.Insert)
                    {
                        VolumeInfo volume = new VolumeInfo(ev.Handle);

                        _volumes.Add(volume);

                        if (Insert != null)
                        {
                            MediaEventArgs mediaEventArgs = new MediaEventArgs(volume, ev.Time);

                            Insert(null, mediaEventArgs);
                        }
                    }
                    else if (ev.EventType == StorageEventType.Eject)
                    {
                        VolumeInfo volumeInfo = RemoveVolume(ev.Handle);

                        if(volumeInfo != null) 
                        {
                            FileSystemManager.ForceRemoveNameSpace(volumeInfo.Name);

                            if (Eject != null)
                            {
                                MediaEventArgs mediaEventArgs = new MediaEventArgs(new VolumeInfo(volumeInfo), ev.Time);

                                Eject(null, mediaEventArgs);
                            }
                        }
                    }
                }
            }           
            finally
            {
                // get rid of this timer
                _events.Dequeue();    
            }
        }
Exemplo n.º 10
0
 private static void Media_Insert(object sender, MediaEventArgs e)
 {
     Debug.Print("Media Insert:");
     PrintVolumeInfo(e.Volume);
 }
Exemplo n.º 11
0
        private static void MessageHandler(object args)
        {
            StorageEvent ev = args as StorageEvent;

            if (ev == null)
                return;

            if (ev.EventType == StorageEventType.Insert)
            {
                VolumeInfo volume = new VolumeInfo(ev.Handle);

                _volumes.Add(volume);

                if (Insert != null)
                {
                    MediaEventArgs mediaEventArgs = new MediaEventArgs(volume, ev.Time);

                    Insert(null, mediaEventArgs);
                }
            }
            else if (ev.EventType == StorageEventType.Eject)
            {
                VolumeInfo volumeInfo = RemoveVolume(ev.Handle);

                FileSystemManager.ForceRemoveNameSpace(volumeInfo.Name);

                if (Eject != null)
                {
                    MediaEventArgs mediaEventArgs = new MediaEventArgs(new VolumeInfo(volumeInfo), ev.Time);

                    Eject(null, mediaEventArgs);
                }
            }
        }
Exemplo n.º 12
0
 private void RemovableMedia_Insert(object sender, MediaEventArgs e)
 {
     _sdCardAvailable = true;
     LogFile.Application("SD card detected.");
     ProcessControl.Instance.InitFromConfigFile();
 }
Exemplo n.º 13
0
 private void RemovableMedia_Eject(object sender, MediaEventArgs e)
 {
     _sdCardAvailable = false;
     Debug.Print("SD card ejected.");
 }
Exemplo n.º 14
0
 private void RemovableMedia_Eject(object sender, MediaEventArgs e)
 {
     sdCardVolume = null;
     Debug.Print("CobraII:  Card Ejected");
 }
        private void OnRemovableMediaInsert(object sender, MediaEventArgs mediaEventArgs)
        {
            Debug.Print("Sd card file system mounted.");

            _onDetectActionThread = new Thread(() => _onSdCardDetected(mediaEventArgs.Volume));
            _onDetectActionThread.Start();
        }
Exemplo n.º 16
0
 private void RemovableMedia_Insert(object sender, MediaEventArgs e)
 {
     sdCardVolume = e.Volume;
     Debug.Print("CobraII: Card Inserted.");
 }
Exemplo n.º 17
0
 private void RemovableMedia_Eject(object sender, MediaEventArgs e)
 {
     Logger.WriteInfo("RPTR", "Media ejected");
 }