Ejemplo n.º 1
0
        async internal void CopyImages(Windows.Storage.StorageFolder rootFolder)
        {
            // Copy images from first folder in root\DCIM.
            var dcimFolder = await rootFolder.GetFolderAsync("DCIM");

            var folderList = await dcimFolder.GetFoldersAsync();

            var cameraFolder = folderList[0];
            var fileList     = await cameraFolder.GetFilesAsync();

            try
            {
                var folderName = "Images " + DateTime.Now.ToString("yyyy-MM-dd HHmmss");
                Windows.Storage.StorageFolder imageFolder = await
                                                            Windows.Storage.KnownFolders.PicturesLibrary.CreateFolderAsync(folderName);

                foreach (Windows.Storage.IStorageItem file in fileList)
                {
                    CopyImage(file, imageFolder);
                }
            }
            catch (Exception e)
            {
                WriteMessageText("Failed to copy images.\n" + e.Message + "\n");
            }
        }
Ejemplo n.º 2
0
        public static async System.Threading.Tasks.Task LoadPhotoTask(string size, string name)
        {
            Windows.Storage.StorageFolder installationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            Windows.Storage.StorageFolder assetsFolder       = await installationFolder.GetFolderAsync("Assets");

            Windows.Storage.StorageFolder imagesFolder = await assetsFolder.GetFolderAsync("Images");

            Windows.Storage.StorageFolder sizeFolder = null;
            if (size.Equals("0.3MP"))
            {
                sizeFolder = await imagesFolder.GetFolderAsync("0_3mp");
            }
            else
            {
                sizeFolder = await imagesFolder.GetFolderAsync(size.ToLower());
            }

            IReadOnlyList <Windows.Storage.StorageFile> files = await sizeFolder.GetFilesAsync();

            foreach (var file in files)
            {
                if (name.Equals(file.Name))
                {
                    using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenReadAsync())
                    {
                        ImageJpg = new byte[fileStream.Size];
                        using (var reader = new Windows.Storage.Streams.DataReader(await file.OpenReadAsync()))
                        {
                            await reader.LoadAsync((uint)fileStream.Size);

                            reader.ReadBytes(ImageJpg);
                        }
                    }
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the specified folder from the current folder.
        /// </summary>
        /// <param name="name">The name of the child folder to retrieve.</param>
        /// <returns>When this method completes successfully, it returns a StorageFolder that represents the child folder.</returns>
        public Task <StorageFolder> GetFolderAsync(string name)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return(Task.Run <StorageFolder>(async() =>
            {
                var f = await _folder.GetFolderAsync(name);
                return f == null ? null : new StorageFolder(f);
            }));
#elif __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
            return(Task.Run <StorageFolder>(() =>
            {
                string folderpath = global::System.IO.Path.Combine(Path, name);

                if (!global::System.IO.Directory.Exists(folderpath))
                {
                    throw new FileNotFoundException();
                }

                return new StorageFolder(folderpath);
            }));
#else
            throw new PlatformNotSupportedException();
#endif
        }
Ejemplo n.º 4
0
        protected async static Task <Windows.Storage.StorageFolder> GetSubFolderBySubPathAsync(Windows.Storage.StorageFolder fldr, string sSubFolderPath)
        {
            Windows.Storage.StorageFolder fldrSub = null;

            try
            {
                fldrSub = await fldr.GetFolderAsync(sSubFolderPath);
            }
            catch (System.IO.FileNotFoundException)
            {
                //NOT EXIST...
            }

            return(fldrSub);
        }
        private async void BtnPlayWav()
        {
            MediaElement mysong = new MediaElement();

            Windows.Storage.StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");

            Windows.Storage.StorageFolder soundsAndVideos = await folder.GetFolderAsync("sounds_videos");

            Windows.Storage.StorageFile file = await soundsAndVideos.GetFileAsync("ingame_2.mp3");

            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            mysong.SetSource(stream, file.ContentType);
            mysong.IsLooping = true;
            mysong.Volume    = 100;
            mysong.Play();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Folder
        /// </summary>
        public static async System.Threading.Tasks.Task <Windows.Storage.StorageFolder> GetFolder(Windows.Storage.StorageFolder folder, string folderName)
        {
            try
            {
                if (folder != null)
                {
                    var f = await folder.GetFolderAsync(folderName);

                    return(f);
                }
            }
            catch (Exception)
            {
                // System.Diagnostics.Debug.WriteLine("Exception while getting file: " + Ex.Message);
            }
            return(null);
        }        /// <summary>
Ejemplo n.º 7
0
        async internal void DisplayImages(Windows.Storage.StorageFolder rootFolder)
        {
            // Display images from first folder in root\DCIM.
            var dcimFolder = await rootFolder.GetFolderAsync("DCIM");

            var folderList = await dcimFolder.GetFoldersAsync();

            var cameraFolder = folderList[0];
            var fileList     = await cameraFolder.GetFilesAsync();

            for (int i = 0; i < fileList.Count; i++)
            {
                var file = (Windows.Storage.StorageFile)fileList[i];
                WriteMessageText(file.Name + "\n");
                DisplayImage(file, i);
            }
        }
Ejemplo n.º 8
0
        private async void PlayOpening()
        {
            Windows.Storage.StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");

            Windows.Storage.StorageFolder soundsAndVideos = await folder.GetFolderAsync("sounds_videos");

            Windows.Storage.StorageFile file = await soundsAndVideos.GetFileAsync(@"Intro Template.mp4");

            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            mysong.SetSource(stream, file.ContentType);
            mysong.AutoPlay  = true;
            mysong.Volume    = 100;
            mysong.IsLooping = true;

            mysong.Play();

            await Task.Delay(22800);

            MainCanvas.Children.Remove(mysong);
            Start_Button.Opacity = 100;
        }
        public async Task Cleanup()
        {
            foreach (var filename in _filenames)
            {
                try
                {
                    var testFile = await _folderForTestFiles.GetFileAsync(filename);

                    if (testFile != null)
                    {
                        await testFile.DeleteAsync();
                    }
                }
                catch
                {
                    Assert.Fail("DeleteAsync (file) exception - error outside tested method");
                }
            }

            foreach (var foldername in _foldernames)
            {
                try
                {
                    var testFolder = await _folderForTestFiles.GetFolderAsync(foldername);

                    if (testFolder != null)
                    {
                        await testFolder.DeleteAsync();
                    }
                }
                catch
                {
                    Assert.Fail("DeleteAsync (folder) exception - error outside tested method");
                }
            }

            await _folderForTestFiles.DeleteAsync();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Attemps to load opencv modules from the specific location
        /// </summary>
        /// <param name="loadDirectory">The directory where the unmanaged modules will be loaded. If it is null, the default location will be used.</param>
        /// <param name="unmanagedModules">The names of opencv modules. e.g. "opencv_cxcore.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded sucessfully</returns>
        /// <remarks>If <paramref name="loadDirectory"/> is null, the default location on windows is the dll's path appended by either "x64" or "x86", depends on the applications current mode.</remarks>
        public static bool LoadUnmanagedModules(String loadDirectory, params String[] unmanagedModules)
        {
#if NETFX_CORE
            if (loadDirectory != null)
            {
                throw new NotImplementedException("Loading modules from a specific directory is not implemented in Windows Store App");
            }

            String subfolder = String.Empty;
            if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows)
            {
                if (IntPtr.Size == 8)
                { //64bit process
                    subfolder = "x64";
                }
                else
                {
                    subfolder = "x86";
                }
            }

            Windows.Storage.StorageFolder installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            loadDirectory = Path.Combine(installFolder.Path, subfolder);

            var t = System.Threading.Tasks.Task.Run(async() =>
            {
                Windows.Storage.StorageFolder loadFolder = await installFolder.GetFolderAsync(subfolder);
                List <string> files = new List <string>();
                foreach (var file in await loadFolder.GetFilesAsync())
                {
                    files.Add(file.Path);
                }
                return(files);
            });
            t.Wait();

            List <String> loadableFiles = t.Result;
#else
            if (loadDirectory == null)
            {
                String subfolder = String.Empty;
                if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows)
                {
                    subfolder = IntPtr.Size == 8 ? "x64" : "x86";
                }

                /*
                 * else if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.MacOSX)
                 * {
                 * subfolder = "..";
                 * }*/

                System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
                FileInfo file = new FileInfo(asm.Location);
                //FileInfo file = new FileInfo(asm.CodeBase);
                DirectoryInfo directory = file.Directory;
                loadDirectory = directory.FullName;

                if (!String.IsNullOrEmpty(subfolder))
                {
                    loadDirectory = Path.Combine(loadDirectory, subfolder);
                }

                if (!Directory.Exists(loadDirectory))
                {
                    //try to find an alternative loadDirectory path
                    //The following code should handle finding the asp.NET BIN folder
                    String altLoadDirectory = Path.GetDirectoryName(asm.CodeBase);
                    if (altLoadDirectory.StartsWith(@"file:\"))
                    {
                        altLoadDirectory = altLoadDirectory.Substring(6);
                    }

                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        altLoadDirectory = Path.Combine(altLoadDirectory, subfolder);
                    }

                    if (!Directory.Exists(altLoadDirectory))
                    {
                        return(false);
                    }
                    else
                    {
                        loadDirectory = altLoadDirectory;
                    }
                }
            }

            String oldDir = Environment.CurrentDirectory;
            Environment.CurrentDirectory = loadDirectory;
#endif
            bool success = true;

            string prefix = string.Empty;

            foreach (String module in unmanagedModules)
            {
                string mName = module;

                //handle special case for universal build
                if (
                    mName.StartsWith("opencv_ffmpeg") && //opencv_ffmpegvvv(_64).dll
                    (IntPtr.Size == 4) //32bit application
                    )
                {
                    mName = module.Replace("_64", String.Empty);
                }

                String fullPath = Path.Combine(loadDirectory, Path.Combine(prefix, mName));

#if NETFX_CORE
                if (loadableFiles.Exists(sf => sf.Equals(fullPath)))
                {
                    IntPtr handle = Toolbox.LoadLibrary(fullPath);
                    success &= (!IntPtr.Zero.Equals(handle));
                }
                else
                {
                    success = false;
                }
#else
                success &= (File.Exists(fullPath) && !IntPtr.Zero.Equals(Toolbox.LoadLibrary(fullPath)));
#endif
            }

#if !NETFX_CORE
            Environment.CurrentDirectory = oldDir;
#endif
            return(success);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Attempts to load opencv modules from the specific location
        /// </summary>
        /// <param name="loadDirectory">The directory where the unmanaged modules will be loaded. If it is null, the default location will be used.</param>
        /// <param name="unmanagedModules">The names of opencv modules. e.g. "opencv_cxcore.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        /// <remarks>If <paramref name="loadDirectory"/> is null, the default location on windows is the dll's path appended by either "x64" or "x86", depends on the applications current mode.</remarks>
        public static bool LoadUnmanagedModules(String loadDirectory, params String[] unmanagedModules)
        {
#if NETFX_CORE
            if (loadDirectory != null)
            {
                throw new NotImplementedException("Loading modules from a specific directory is not implemented in Windows Store App");
            }

            String subfolder = String.Empty;
            if (Emgu.Util.Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows) //|| Platform.OperationSystem == Emgu.Util.TypeEnum.OS.WindowsPhone)
            {
                if (IntPtr.Size == 8)
                { //64bit process
#if UNITY_METRO
                    subfolder = "x86_64";
#else
                    subfolder = String.Empty;
#endif
                }
                else
                {
                    subfolder = String.Empty;
                }
            }

            Windows.Storage.StorageFolder installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

#if UNITY_METRO
            loadDirectory = Path.Combine(
                Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(installFolder.Path))))
                , "Plugins", "Metro", subfolder);
#else
            loadDirectory = Path.Combine(installFolder.Path, subfolder);
#endif

            var t = System.Threading.Tasks.Task.Run(async() =>
            {
                List <string> files = new List <string>();
                Windows.Storage.StorageFolder loadFolder = installFolder;
                try
                {
                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        loadFolder = await installFolder.GetFolderAsync(subfolder);
                    }

                    foreach (var file in await loadFolder.GetFilesAsync())
                    {
                        files.Add(file.Name);
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("Unable to retrieve files in folder '{0}':{1}", loadFolder.Path, e.StackTrace));
                }

                return(files);
            });
            t.Wait();

            List <String> loadableFiles = t.Result;
#else
            if (loadDirectory == null)
            {
                String subfolder = String.Empty;
#if UNITY_EDITOR_WIN
                subfolder = IntPtr.Size == 8 ? "x86_64" : "x86";
#elif UNITY_STANDALONE_WIN
#else
                if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows)
                {
                    subfolder = IntPtr.Size == 8 ? "x64" : "x86";
                }
#endif

                /*
                 * else if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.MacOSX)
                 * {
                 * subfolder = "..";
                 * }*/
#if NETSTANDARD1_4
                loadDirectory = new DirectoryInfo(".").FullName;
#else
                System.Reflection.Assembly asm = typeof(CvInvoke).Assembly; //System.Reflection.Assembly.GetExecutingAssembly();
                if ((String.IsNullOrEmpty(asm.Location) || !File.Exists(asm.Location)) && AppDomain.CurrentDomain.BaseDirectory != null)
                {
                    //if may be running in a debugger visualizer under a unit test in this case
                    String        visualStudioDir       = AppDomain.CurrentDomain.BaseDirectory;
                    DirectoryInfo visualStudioDirInfo   = new DirectoryInfo(visualStudioDir);
                    String        debuggerVisualzerPath =
                        Path.Combine(Path.Combine(Path.Combine(
                                                      visualStudioDirInfo.Parent.FullName, "Packages"), "Debugger"), "Visualizers");

                    if (Directory.Exists(debuggerVisualzerPath))
                    {
                        loadDirectory = debuggerVisualzerPath;
                    }
                    else
                    {
                        loadDirectory = String.Empty;
                    }

/*
 *             loadDirectory = Path.GetDirectoryName(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path);
 *
 *             DirectoryInfo dir = new DirectoryInfo(loadDirectory);
 *             string subdir = String.Join(";", Array.ConvertAll(dir.GetDirectories(), d => d.ToString()));
 *
 *             throw new Exception(String.Format(
 *                "The Emgu.CV.dll assembly path (typeof (CvInvoke).Assembly.Location) '{0}' is invalid." +
 *                Environment.NewLine
 + " Other possible path (System.Reflection.Assembly.GetExecutingAssembly().Location): '{1}';" +
 +                Environment.NewLine
 + " Other possible path (Path.GetDirectoryName(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path): '{2}';" +
 +                Environment.NewLine
 + " Other possible path (System.Reflection.Assembly.GetExecutingAssembly().CodeBase): '{3};'" +
 +                Environment.NewLine
 + " Other possible path (typeof(CvInvoke).Assembly.CodeBase): '{4}'" +
 +                Environment.NewLine
 + " Other possible path (AppDomain.CurrentDomain.BaseDirectory): '{5}'" +
 +                Environment.NewLine
 + " subfolder name: '{6}'",
 +                asm.Location,
 +                Path.GetDirectoryName(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path),
 +                loadDirectory + ": subdir '" + subdir +"'",
 +                System.Reflection.Assembly.GetExecutingAssembly().CodeBase,
 +                typeof(CvInvoke).Assembly.Location,
 +                AppDomain.CurrentDomain.BaseDirectory,
 +                subfolder
 +                ));
 */
                }
                else
                {
                    loadDirectory = Path.GetDirectoryName(asm.Location);
                }

                /*
                 * FileInfo file = new FileInfo(asm.Location);
                 * //FileInfo file = new FileInfo(asm.CodeBase);
                 * DirectoryInfo directory = file.Directory;
                 * loadDirectory = directory.FullName;
                 */
#endif
                if (!String.IsNullOrEmpty(subfolder))
                {
                    var temp = Path.Combine(loadDirectory, subfolder);
                    if (Directory.Exists(temp))
                    {
                        loadDirectory = temp;
                    }
                    else
                    {
                        loadDirectory = Path.Combine(Path.GetFullPath("."), subfolder);
                    }
                }

#if (UNITY_STANDALONE_WIN && !UNITY_EDITOR_WIN)
                if (String.IsNullOrEmpty(asm.Location) || !File.Exists(asm.Location))
                {
                    Debug.WriteLine(String.Format("UNITY_STANDALONE_WIN: asm.Location is invalid: '{0}'", asm.Location));
                    return(false);
                }


                FileInfo      file      = new FileInfo(asm.Location);
                DirectoryInfo directory = file.Directory;
                if (directory.Parent != null)
                {
                    String unityAltFolder = Path.Combine(directory.Parent.FullName, "Plugins");

                    if (Directory.Exists(unityAltFolder))
                    {
                        loadDirectory = unityAltFolder;
                    }
                    else
                    {
                        Debug.WriteLine("No suitable directory found to load unmanaged modules");
                        return(false);
                    }
                }
#elif __ANDROID__ || UNITY_ANDROID || NETSTANDARD1_4
#else
                if (!Directory.Exists(loadDirectory))
                {
                    //try to find an alternative loadDirectory path
                    //The following code should handle finding the asp.NET BIN folder
                    String altLoadDirectory = Path.GetDirectoryName(asm.CodeBase);
                    if (!String.IsNullOrEmpty(altLoadDirectory) && altLoadDirectory.StartsWith(@"file:\"))
                    {
                        altLoadDirectory = altLoadDirectory.Substring(6);
                    }

                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        altLoadDirectory = Path.Combine(altLoadDirectory, subfolder);
                    }

                    if (!Directory.Exists(altLoadDirectory))
                    {
                        if (String.IsNullOrEmpty(asm.Location) || !File.Exists(asm.Location))
                        {
                            Debug.WriteLine(String.Format("asm.Location is invalid: '{0}'", asm.Location));
                            return(false);
                        }
                        FileInfo      file      = new FileInfo(asm.Location);
                        DirectoryInfo directory = file.Directory;
#if UNITY_EDITOR_WIN
                        if (directory.Parent != null && directory.Parent.Parent != null)
                        {
                            String unityAltFolder =
                                Path.Combine(
                                    Path.Combine(Path.Combine(Path.Combine(directory.Parent.Parent.FullName, "Assets"), "Emgu.CV"), "Plugins"),
                                    subfolder);

                            Debug.WriteLine("Trying unityAltFolder: " + unityAltFolder);
                            if (Directory.Exists(unityAltFolder))
                            {
                                loadDirectory = unityAltFolder;
                            }
                            else
                            {
                                Debug.WriteLine("No suitable directory found to load unmanaged modules");
                                return(false);
                            }
                        }
                        else
#elif (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
                        if (directory.Parent != null && directory.Parent.Parent != null)
                        {
                            String unityAltFolder =
                                Path.Combine(Path.Combine(Path.Combine(
                                                              Path.Combine(Path.Combine(directory.Parent.Parent.FullName, "Assets"), "Plugins"),
                                                              "emgucv.bundle"), "Contents"), "MacOS");

                            if (Directory.Exists(unityAltFolder))
                            {
                                loadDirectory = unityAltFolder;
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
#endif
                        {
                            Debug.WriteLine("No suitable directory found to load unmanaged modules");
                            return(false);
                        }
                    }
                    else
                    {
                        loadDirectory = altLoadDirectory;
                    }
                }
#endif
            }
#if !(NETSTANDARD1_4)
            String oldDir = Environment.CurrentDirectory;
            if (!String.IsNullOrEmpty(loadDirectory) && Directory.Exists(loadDirectory))
            {
                Environment.CurrentDirectory = loadDirectory;
            }
#endif
#endif

            System.Diagnostics.Debug.WriteLine(String.Format("Loading open cv binary from {0}", loadDirectory));
            bool success = true;

            string prefix = string.Empty;

            foreach (String module in unmanagedModules)
            {
                string mName = module;

                //handle special case for universal build
                if (
                    mName.StartsWith("opencv_ffmpeg") && //opencv_ffmpegvvv(_64).dll
                    (IntPtr.Size == 4) //32bit application
                    )
                {
                    mName = module.Replace("_64", String.Empty);
                }

                String fullPath = Path.Combine(prefix, mName);

#if NETFX_CORE
                if (loadableFiles.Exists(sf => sf.Equals(fullPath)))
                {
                    IntPtr handle = Toolbox.LoadLibrary(fullPath);
                    success &= (!IntPtr.Zero.Equals(handle));
                }
                else
                {
                    success = false;
                }
#else
                //Use absolute path for Windows Desktop
                fullPath = Path.Combine(loadDirectory, fullPath);

                bool fileExist = File.Exists(fullPath);
                if (!fileExist)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("File {0} do not exist.", fullPath));
                }
                bool fileExistAndLoaded = fileExist && !IntPtr.Zero.Equals(Toolbox.LoadLibrary(fullPath));
                if (fileExist && (!fileExistAndLoaded))
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("File {0} cannot be loaded.", fullPath));
                }
                success &= fileExistAndLoaded;
#endif
            }

#if !(NETFX_CORE || NETSTANDARD1_4)
            Environment.CurrentDirectory = oldDir;
#endif
            return(success);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Attempts to load opencv modules from the specific location
        /// </summary>
        /// <param name="loadDirectory">The directory where the unmanaged modules will be loaded. If it is null, the default location will be used.</param>
        /// <param name="unmanagedModules">The names of opencv modules. e.g. "opencv_cxcore.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        /// <remarks>If <paramref name="loadDirectory"/> is null, the default location on windows is the dll's path appended by either "x64" or "x86", depends on the applications current mode.</remarks>
        public static bool LoadUnmanagedModules(String loadDirectory, params String[] unmanagedModules)
        {
#if NETFX_CORE
            if (loadDirectory != null)
            {
                throw new NotImplementedException("Loading modules from a specific directory is not implemented in Windows Store App");
            }

            String subfolder = String.Empty;
            if (Emgu.Util.Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows) //|| Platform.OperationSystem == Emgu.Util.TypeEnum.OS.WindowsPhone)
            {
                if (IntPtr.Size == 8)
                { //64bit process
#if UNITY_METRO
                    subfolder = "x86_64";
#else
                    subfolder = String.Empty;
#endif
                }
                else
                {
                    subfolder = String.Empty;
                }
            }

            Windows.Storage.StorageFolder installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

#if UNITY_METRO
            loadDirectory = Path.Combine(
                Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(installFolder.Path))))
                , "Plugins", "Metro", subfolder);
#else
            loadDirectory = Path.Combine(installFolder.Path, subfolder);
#endif

            var t = System.Threading.Tasks.Task.Run(async() =>
            {
                List <string> files = new List <string>();
                Windows.Storage.StorageFolder loadFolder = installFolder;
                try
                {
                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        loadFolder = await installFolder.GetFolderAsync(subfolder);
                    }

                    foreach (var file in await loadFolder.GetFilesAsync())
                    {
                        files.Add(file.Name);
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("Unable to retrieve files in folder '{0}':{1}", loadFolder.Path, e.StackTrace));
                }

                return(files);
            });
            t.Wait();

            List <String> loadableFiles = t.Result;
#else
            if (loadDirectory == null)
            {
                String subfolder = String.Empty;
#if UNITY_EDITOR_WIN
                subfolder = IntPtr.Size == 8 ? "x86_64" : "x86";
#elif UNITY_STANDALONE_WIN
#else
                if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows)
                {
                    subfolder = IntPtr.Size == 8 ? "x64" : "x86";
                }
#endif

                /*
                 * else if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.MacOSX)
                 * {
                 * subfolder = "..";
                 * }*/

                System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
                FileInfo file = new FileInfo(asm.Location);
                //FileInfo file = new FileInfo(asm.CodeBase);
                DirectoryInfo directory = file.Directory;
                loadDirectory = directory.FullName;

                if (!String.IsNullOrEmpty(subfolder))
                {
                    loadDirectory = Path.Combine(loadDirectory, subfolder);
                }

#if (UNITY_STANDALONE_WIN && !UNITY_EDITOR_WIN)
                if (directory.Parent != null)
                {
                    String unityAltFolder = Path.Combine(directory.Parent.FullName, "Plugins");

                    if (Directory.Exists(unityAltFolder))
                    {
                        loadDirectory = unityAltFolder;
                    }
                    else
                    {
                        Debug.WriteLine("No suitable directory found to load unmanaged modules");
                        return(false);
                    }
                }
#else
                if (!Directory.Exists(loadDirectory))
                {
                    //try to find an alternative loadDirectory path
                    //The following code should handle finding the asp.NET BIN folder
                    String altLoadDirectory = Path.GetDirectoryName(asm.CodeBase);
                    if (altLoadDirectory.StartsWith(@"file:\"))
                    {
                        altLoadDirectory = altLoadDirectory.Substring(6);
                    }

                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        altLoadDirectory = Path.Combine(altLoadDirectory, subfolder);
                    }

                    if (!Directory.Exists(altLoadDirectory))
                    {
#if UNITY_EDITOR_WIN
                        if (directory.Parent != null && directory.Parent.Parent != null)
                        {
                            String unityAltFolder =
                                Path.Combine(
                                    Path.Combine(Path.Combine(directory.Parent.Parent.FullName, "Assets"), "Plugins"),
                                    subfolder);

                            if (Directory.Exists(unityAltFolder))
                            {
                                loadDirectory = unityAltFolder;
                            }
                            else
                            {
                                Debug.WriteLine("No suitable directory found to load unmanaged modules");
                                return(false);
                            }
                        }
                        else
#elif (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
                        if (directory.Parent != null && directory.Parent.Parent != null)
                        {
                            String unityAltFolder =
                                Path.Combine(Path.Combine(Path.Combine(
                                                              Path.Combine(Path.Combine(directory.Parent.Parent.FullName, "Assets"), "Plugins"),
                                                              "emgucv.bundle"), "Contents"), "MacOS");

                            if (Directory.Exists(unityAltFolder))
                            {
                                loadDirectory = unityAltFolder;
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
#endif
                        {
                            Debug.WriteLine("No suitable directory found to load unmanaged modules");
                            return(false);
                        }
                    }
                    else
                    {
                        loadDirectory = altLoadDirectory;
                    }
                }
#endif
            }

            String oldDir = Environment.CurrentDirectory;
            Environment.CurrentDirectory = loadDirectory;
#endif

            System.Diagnostics.Debug.WriteLine(String.Format("Loading open cv binary from {0}", loadDirectory));
            bool success = true;

            string prefix = string.Empty;

            foreach (String module in unmanagedModules)
            {
                string mName = module;

                //handle special case for universal build
                if (
                    mName.StartsWith("opencv_ffmpeg") && //opencv_ffmpegvvv(_64).dll
                    (IntPtr.Size == 4) //32bit application
                    )
                {
                    mName = module.Replace("_64", String.Empty);
                }

                String fullPath = Path.Combine(prefix, mName);

                /*
                 * if (Emgu.Util.Platform.OperationSystem != Emgu.Util.TypeEnum.OS.WindowsPhone)
                 * {
                 * //Do not use absolute path for Windows Phone
                 * fullPath = Path.Combine(loadDirectory, fullPath);
                 * }*/

#if NETFX_CORE
                if (loadableFiles.Exists(sf => sf.Equals(fullPath)))
                {
                    IntPtr handle = Toolbox.LoadLibrary(fullPath);
                    success &= (!IntPtr.Zero.Equals(handle));
                }
                else
                {
                    success = false;
                }
#else
                bool fileExist = File.Exists(fullPath);
                if (!fileExist)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("File {0} do not exist.", fullPath));
                }
                bool fileExistAndLoaded = fileExist && !IntPtr.Zero.Equals(Toolbox.LoadLibrary(fullPath));
                if (fileExist && (!fileExistAndLoaded))
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("File {0} cannot be loaded.", fullPath));
                }
                success &= fileExistAndLoaded;
#endif
            }

#if !NETFX_CORE
            Environment.CurrentDirectory = oldDir;
#endif
            return(success);
        }
Ejemplo n.º 13
0
        private async void MediaPlayerElement_Loaded(object sender, RoutedEventArgs e)
        {
            MediaPlayerElement mediaPlayerElement = sender as MediaPlayerElement;

            if (mediaPlayerElement != null)
            {
                System.Diagnostics.Debug.WriteLine("MPE: " + mediaPlayerElement.Name + " loaded");
                MediaItem item = GetItem();
                if (item != null)
                {
                    var player = new MediaPlayer();
                    if (player != null)
                    {
                        string url = item.mediaUrl;
                        player.MediaEnded += Player_MediaEnded;
                        player.AutoPlay    = true;
                        player.IsMuted     = false;
                        if (!url.StartsWith("video://"))
                        {
                            var uri = new Uri(url);
                            if (uri != null)
                            {
                                player.Source = Windows.Media.Core.MediaSource.CreateFromUri(uri);
                            }
                        }
                        else
                        {
                            var path = url.Replace("video://", "");
                            if (path != null)
                            {
                                try
                                {
                                    Windows.Storage.StorageFolder folder = Windows.Storage.KnownFolders.VideosLibrary;
                                    Windows.Storage.StorageFile   file   = null;
                                    string ext       = System.IO.Path.GetExtension(path);
                                    string filename  = System.IO.Path.GetFileName(path);
                                    string directory = System.IO.Path.GetDirectoryName(path);
                                    while (!string.IsNullOrEmpty(directory))
                                    {
                                        string subdirectory = directory;
                                        int    pos          = -1;
                                        if ((pos = directory.IndexOf('\\')) > 0)
                                        {
                                            subdirectory = directory.Substring(0, pos);
                                        }
                                        folder = await folder.GetFolderAsync(subdirectory);

                                        if (folder != null)
                                        {
                                            if (pos > 0)
                                            {
                                                directory = directory.Substring(pos + 1);
                                            }
                                            else
                                            {
                                                directory = string.Empty;
                                            }
                                        }
                                    }
                                    if (folder != null)
                                    {
                                        file = await folder.GetFileAsync(filename);

                                        if (file != null)
                                        {
                                            player.Source = Windows.Media.Core.MediaSource.CreateFromStorageFile(file);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Debug.WriteLine("Exception while opening file: " + ex.Message);
                                }
                            }
                        }
                        mediaPlayerElement.SetMediaPlayer(player);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// GetFileFromLocalPathUrl
        /// Return the StorageFile associated with the url
        /// </summary>
        /// <param name="PosterUrl">Url string of the content</param>
        /// <returns>StorageFile</returns>
        private async System.Threading.Tasks.Task <Windows.Storage.StorageFile> GetFileFromLocalPathUrl(string PosterUrl)
        {
            string path = null;

            Windows.Storage.StorageFolder folder = null;
            if (PosterUrl.ToLower().StartsWith("picture://"))
            {
                folder = Windows.Storage.KnownFolders.PicturesLibrary;
                path   = PosterUrl.Replace("picture://", "");
            }
            else if (PosterUrl.ToLower().StartsWith("music://"))
            {
                folder = Windows.Storage.KnownFolders.MusicLibrary;
                path   = PosterUrl.Replace("music://", "");
            }
            else if (PosterUrl.ToLower().StartsWith("video://"))
            {
                folder = Windows.Storage.KnownFolders.VideosLibrary;
                path   = PosterUrl.Replace("video://", "");
            }
            else if (PosterUrl.ToLower().StartsWith("file://"))
            {
                path = PosterUrl.Replace("file://", "");
            }
            else
            {
                path = PosterUrl;
            }
            Windows.Storage.StorageFile file = null;
            try
            {
                if (folder != null)
                {
                    string ext       = System.IO.Path.GetExtension(path);
                    string filename  = System.IO.Path.GetFileName(path);
                    string directory = System.IO.Path.GetDirectoryName(path);
                    while (!string.IsNullOrEmpty(directory))
                    {
                        string subdirectory = directory;
                        int    pos          = -1;
                        if ((pos = directory.IndexOf('\\')) > 0)
                        {
                            subdirectory = directory.Substring(0, pos);
                        }
                        folder = await folder.GetFolderAsync(subdirectory);

                        if (folder != null)
                        {
                            if (pos > 0)
                            {
                                directory = directory.Substring(pos + 1);
                            }
                            else
                            {
                                directory = string.Empty;
                            }
                        }
                    }
                    if (folder != null)
                    {
                        file = await folder.GetFileAsync(filename);
                    }
                }
                else
                {
                    file = await Windows.Storage.StorageFile.GetFileFromPathAsync(path);
                }
            }
            catch (Exception e)
            {
                LogMessage("Exception while opening file: " + PosterUrl + " exception: " + e.Message);
            }
            return(file);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Attempts to load opencv modules from the specific location
        /// </summary>
        /// <param name="loadDirectory">The directory where the unmanaged modules will be loaded. If it is null, the default location will be used.</param>
        /// <param name="unmanagedModules">The names of opencv modules. e.g. "opencv_core.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        /// <remarks>If <paramref name="loadDirectory"/> is null, the default location on windows is the dll's path appended by either "x64" or "x86", depends on the applications current mode.</remarks>
        public static bool LoadUnmanagedModules(String loadDirectory, params String[] unmanagedModules)
        {
#if NETFX_CORE
            if (loadDirectory != null)
            {
                throw new NotImplementedException("Loading modules from a specific directory is not implemented in Windows Store App");
            }

            String subfolder = String.Empty;
            if (Emgu.Util.Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows) //|| Platform.OperationSystem == Emgu.Util.TypeEnum.OS.WindowsPhone)
            {
                if (IntPtr.Size == 8)
                { //64bit process
#if UNITY_METRO
                    subfolder = "x86_64";
#else
                    subfolder = String.Empty;
#endif
                }
                else
                {
                    subfolder = String.Empty;
                }
            }

            Windows.Storage.StorageFolder installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

#if UNITY_METRO
            loadDirectory = Path.Combine(
                Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(installFolder.Path))))
                , "Plugins", "Metro", subfolder);
#else
            loadDirectory = Path.Combine(installFolder.Path, subfolder);
#endif

            var t = System.Threading.Tasks.Task.Run(async() =>
            {
                List <string> files = new List <string>();
                Windows.Storage.StorageFolder loadFolder = installFolder;
                try
                {
                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        loadFolder = await installFolder.GetFolderAsync(subfolder);
                    }

                    foreach (var file in await loadFolder.GetFilesAsync())
                    {
                        files.Add(file.Name);
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("Unable to retrieve files in folder '{0}':{1}", loadFolder.Path, e.StackTrace));
                }

                return(files);
            });
            t.Wait();

            List <String> loadableFiles = t.Result;
#else
            if (loadDirectory == null)
            {
                String subfolder = String.Empty;
#if UNITY_EDITOR_WIN
                subfolder = IntPtr.Size == 8 ? "x86_64" : "x86";
#elif UNITY_STANDALONE_WIN
#else
                if (Platform.OperationSystem == Emgu.Util.Platform.OS.Windows ||
                    Platform.OperationSystem == Emgu.Util.Platform.OS.Linux)
                {
                    //var fd = RuntimeInformation.FrameworkDescription;
                    if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
                    {
                        subfolder = "x86";
                    }
                    else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
                    {
                        subfolder = "x64";
                    }
                    else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm)
                    {
                        subfolder = "arm";
                    }
                    else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
                    {
                        subfolder = "arm64";
                    }

                    //subfolder = IntPtr.Size == 8 ? "x64" : "x86";
                }
#endif

                System.Reflection.Assembly asm = typeof(CvInvoke).Assembly; //System.Reflection.Assembly.GetExecutingAssembly();
                if ((String.IsNullOrEmpty(asm.Location) || !File.Exists(asm.Location)))
                {
                    if (String.IsNullOrEmpty(AppDomain.CurrentDomain.BaseDirectory))
                    {
                        loadDirectory = String.Empty;
                    }
                    else
                    {
                        //we may be running in a debugger visualizer under a unit test in this case
                        String        baseDirectory          = AppDomain.CurrentDomain.BaseDirectory;
                        DirectoryInfo baseDirectoryInfo      = new DirectoryInfo(baseDirectory);
                        String        debuggerVisualizerPath = String.Empty;
                        if (baseDirectoryInfo.Parent != null)
                        {
                            debuggerVisualizerPath = Path.Combine(baseDirectoryInfo.Parent.FullName, "Packages", "Debugger", "Visualizers");
                        }

                        if (!debuggerVisualizerPath.Equals(String.Empty) && Directory.Exists(debuggerVisualizerPath))
                        {
                            loadDirectory = debuggerVisualizerPath;
                        }
                        else
                        {
                            loadDirectory = baseDirectoryInfo.FullName;
                            if (!Directory.Exists(Path.Combine(baseDirectoryInfo.FullName, subfolder)))
                            {
                                subfolder = String.Empty;
                            }
                        }

                        /*
                         * loadDirectory = Path.GetDirectoryName(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path);
                         *
                         * DirectoryInfo dir = new DirectoryInfo(loadDirectory);
                         * string subdir = String.Join(";", Array.ConvertAll(dir.GetDirectories(), d => d.ToString()));
                         *
                         * throw new Exception(String.Format(
                         *    "The Emgu.CV.dll assembly path (typeof (CvInvoke).Assembly.Location) '{0}' is invalid." +
                         *    Environment.NewLine
                         + " Other possible path (System.Reflection.Assembly.GetExecutingAssembly().Location): '{1}';" +
                         +    Environment.NewLine
                         + " Other possible path (Path.GetDirectoryName(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path): '{2}';" +
                         +    Environment.NewLine
                         + " Other possible path (System.Reflection.Assembly.GetExecutingAssembly().CodeBase): '{3};'" +
                         +    Environment.NewLine
                         + " Other possible path (typeof(CvInvoke).Assembly.CodeBase): '{4}'" +
                         +    Environment.NewLine
                         + " Other possible path (AppDomain.CurrentDomain.BaseDirectory): '{5}'" +
                         +    Environment.NewLine
                         + " subfolder name: '{6}'",
                         +    asm.Location,
                         +    Path.GetDirectoryName(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path),
                         +    loadDirectory + ": subdir '" + subdir +"'",
                         +    System.Reflection.Assembly.GetExecutingAssembly().CodeBase,
                         +    typeof(CvInvoke).Assembly.Location,
                         +    AppDomain.CurrentDomain.BaseDirectory,
                         +    subfolder
                         +    ));
                         */
                    }
                }
                else
                {
                    loadDirectory = Path.GetDirectoryName(asm.Location);
                    if ((loadDirectory != null) && (!Directory.Exists(Path.Combine(loadDirectory, subfolder))))
                    {
                        subfolder = String.Empty;
                    }
                }

                /*
                 * FileInfo file = new FileInfo(asm.Location);
                 * //FileInfo file = new FileInfo(asm.CodeBase);
                 * DirectoryInfo directory = file.Directory;
                 * loadDirectory = directory.FullName;
                 */

                if (!String.IsNullOrEmpty(subfolder))
                {
                    var temp = Path.Combine(loadDirectory, subfolder);
                    if (Directory.Exists(temp))
                    {
                        loadDirectory = temp;
                    }
                    else
                    {
                        loadDirectory = Path.Combine(Path.GetFullPath("."), subfolder);
                    }
                }

#if (UNITY_STANDALONE_WIN && !UNITY_EDITOR_WIN)
                if (String.IsNullOrEmpty(asm.Location) || !File.Exists(asm.Location))
                {
                    Debug.WriteLine(String.Format("UNITY_STANDALONE_WIN: asm.Location is invalid: '{0}'", asm.Location));
                    return(false);
                }


                FileInfo      file      = new FileInfo(asm.Location);
                DirectoryInfo directory = file.Directory;
                if (directory.Parent != null)
                {
                    String unityAltFolder = Path.Combine(directory.Parent.FullName, "Plugins");

                    if (Directory.Exists(unityAltFolder))
                    {
                        loadDirectory = unityAltFolder;
                    }
                    else
                    {
                        Debug.WriteLine("No suitable directory found to load unmanaged modules");
                        return(false);
                    }
                }
#elif UNITY_ANDROID
#else
                if (!Directory.Exists(loadDirectory))
                {
                    //try to find an alternative loadDirectory path
                    //The following code should handle finding the asp.NET BIN folder
                    String altLoadDirectory = Path.GetDirectoryName(asm.CodeBase);
                    if (!String.IsNullOrEmpty(altLoadDirectory) && altLoadDirectory.StartsWith(@"file:\"))
                    {
                        altLoadDirectory = altLoadDirectory.Substring(6);
                    }

                    if (!String.IsNullOrEmpty(subfolder))
                    {
                        altLoadDirectory = Path.Combine(altLoadDirectory, subfolder);
                    }

                    if (!Directory.Exists(altLoadDirectory))
                    {
                        if (String.IsNullOrEmpty(asm.Location) || !File.Exists(asm.Location))
                        {
                            Debug.WriteLine(String.Format("asm.Location is invalid: '{0}'", asm.Location));
                            return(false);
                        }
                        FileInfo      file      = new FileInfo(asm.Location);
                        DirectoryInfo directory = file.Directory;
#if UNITY_EDITOR_WIN
                        if (directory.Parent != null && directory.Parent.Parent != null)
                        {
                            String unityAltFolder =
                                Path.Combine(
                                    Path.Combine(Path.Combine(Path.Combine(directory.Parent.Parent.FullName, "Assets"), "Emgu.CV"), "Plugins"),
                                    subfolder);

                            Debug.WriteLine("Trying unityAltFolder: " + unityAltFolder);
                            if (Directory.Exists(unityAltFolder))
                            {
                                loadDirectory = unityAltFolder;
                            }
                            else
                            {
                                Debug.WriteLine("No suitable directory found to load unmanaged modules");
                                return(false);
                            }
                        }
                        else
#elif (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
                        if (directory.Parent != null && directory.Parent.Parent != null)
                        {
                            String unityAltFolder =
                                Path.Combine(Path.Combine(Path.Combine(
                                                              Path.Combine(Path.Combine(directory.Parent.Parent.FullName, "Assets"), "Plugins"),
                                                              "emgucv.bundle"), "Contents"), "MacOS");

                            if (Directory.Exists(unityAltFolder))
                            {
                                loadDirectory = unityAltFolder;
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
#endif
                        {
                            System.Diagnostics.Debug.WriteLine("No suitable directory found to load unmanaged modules");
                            return(false);
                        }
                    }
                    else
                    {
                        loadDirectory = altLoadDirectory;
                    }
                }
#endif
            }

            String oldDir = String.Empty;

            bool addDllDirectorySuccess = false;
            if (!String.IsNullOrEmpty(loadDirectory) && Directory.Exists(loadDirectory))
            {
                if (Platform.ClrType == Platform.Clr.DotNetNative)
                {
                    //do nothing
                }
                else if (Emgu.Util.Platform.OperationSystem == Emgu.Util.Platform.OS.Windows)
                {
                    addDllDirectorySuccess = Emgu.Util.Toolbox.AddDllDirectory(loadDirectory);
                    if (!addDllDirectorySuccess)
                    {
                        System.Diagnostics.Debug.WriteLine(String.Format("Failed to add dll directory: {0}", loadDirectory));
                    }
                }
                else if (Emgu.Util.Platform.OperationSystem == Emgu.Util.Platform.OS.IOS)
                {
                    //do nothing
                    System.Diagnostics.Debug.WriteLine("iOS required static linking, Setting loadDirectory is not supported");
                }
                else
                {
                    oldDir = Environment.CurrentDirectory;
                    Environment.CurrentDirectory = loadDirectory;
                }
            }

            if (addDllDirectorySuccess)
            {
                System.Diagnostics.Debug.WriteLine(
                    String.Format(
                        "Loading Open CV binary for default locations. Current directory: {0}; Additional load folder: {1}",
                        Environment.CurrentDirectory,
                        loadDirectory));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(
                    String.Format(
                        "Loading Open CV binary for default locations. Current directory: {0}",
                        Environment.CurrentDirectory));
            }
#endif

            bool   success = true;
            string prefix  = string.Empty;
            foreach (String module in unmanagedModules)
            {
                string mName = module;

                //handle special case for universal build
                if (
                    mName.StartsWith("opencv_videoio_ffmpeg") && //opencv_ffmpegvvv(_64).dll
                    (IntPtr.Size == 4)   //32bit application
                    )
                {
                    mName = module.Replace("_64", String.Empty);
                }

                bool optionalComponent = mName.Contains("ffmpeg");

                String fullPath = Path.Combine(prefix, mName);

                //Use absolute path for Windows Desktop
                fullPath = Path.Combine(loadDirectory, fullPath);

                bool fileExist = File.Exists(fullPath);
                bool loaded    = false;

                if (fileExist)
                {
                    //Try to load using the full path
                    System.Diagnostics.Trace.WriteLine(String.Format("Found full path {0} for {1}. Trying to load it.", fullPath, mName));
                    loaded = !IntPtr.Zero.Equals(Toolbox.LoadLibrary(fullPath));
                    if (loaded)
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("{0} loaded.", mName));
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("Failed to load {0} from {1}.", mName, fullPath));
                    }
                }
                if (loaded)
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("Trying to load {0} using default path.", mName));
                    loaded = !IntPtr.Zero.Equals(Toolbox.LoadLibrary(mName));
                    if (loaded)
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("{0} loaded using default path", mName));
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("Failed to load {0} using default path", mName));
                    }
                }

                if (!loaded)
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("!!! Failed to load {0}.", mName));
                }

                if (!optionalComponent)
                {
                    success &= loaded;
                }
            }

            if (!oldDir.Equals(String.Empty))
            {
                Environment.CurrentDirectory = oldDir;
            }

            return(success);
        }