예제 #1
0
        public static void analyseRecycleBin()
        {
            try {
                var _returnList = new List<string>();
                var _shell = new Shell();
                var countedItemSize = 0;

                initWorker();
                _binWorker.RunWorkerAsync();
                _binWorker.DoWork += (o, e) => {
                    var _recBin = _shell.NameSpace(10);

                    // Size of Items in Byte
                    foreach (FolderItem2 item in _recBin.Items()) {
                        countedItemSize += item.Size;
                    }

                    _returnList.Add(_recBin.Items().Count.ToString());
                    _returnList.Add(countedItemSize.ToString());
                    _returnList.Add(DateTime.Now.ToString("g"));
                    Marshal.FinalReleaseComObject(_shell);
                };

                _binWorker.RunWorkerCompleted += (o, e) => {
                    if (_stopBinScan != null) {
                        _stopBinScan(_returnList);
                    }
                };
            }
            catch(Exception ex) {
                MessageBox.Show(ex.Message, "analyseRecycleBin()");
            }
        }
예제 #2
0
        /// <summary>
        /// Returns the currently selected path from windows explorer.
        /// Can point into a directory, a file inside a zip file, control panel, whatever.
        /// </summary>
        /// <returns></returns>
        public static string GetTopSelectedPathFromWindowsExplorer()
        {
            IShellDispatch5 shell = new Shell();

            var windows = shell.Windows();

            var explorerHandles = new Dictionary<IntPtr, dynamic>();

            foreach (var window in windows)
            {
                explorerHandles.Add((IntPtr) window.HWND, window);
            }

            IntPtr i = GetForegroundWindow();

            while (i != IntPtr.Zero && !explorerHandles.ContainsKey(i))
            {
                i = GetWindow(i, GetWindow_Cmd.GW_HWNDNEXT);
            }

            string path = null;
            if (i != IntPtr.Zero)
            {
                var window = explorerHandles[i];
                path = ((IShellFolderViewDual2) window.Document).FocusedItem.Path;
            }
            return path;
        }
예제 #3
0
        public static string ZipFolder(string sourceFolder, string destinationFile)
        {
            byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            if (File.Exists(destinationFile))
            {
                File.Delete(destinationFile);
            }

            FileStream fs = File.Create(destinationFile);
            fs.Write(emptyzip, 0, emptyzip.Length);
            fs.Flush();

            fs.Close();
            fs = null;
            File.SetAttributes(destinationFile, FileAttributes.Normal);
            Shell objShell = new Shell();
            Folder destination = objShell.NameSpace(destinationFile);
            Folder source = objShell.NameSpace(sourceFolder);
            FolderItems items = source.Items();
            destination.CopyHere(items, 20);
            System.Threading.Thread.Sleep(1000);

            return destinationFile;
        }
예제 #4
0
        public static Dictionary<string, string> GetExtendedProperties(string path)
        {
            Dictionary<string, string> properties = null;

            if (!File.Exists(path))
            {
                return properties;
            }

            var dirName = Path.GetDirectoryName(path);

            Shell shell = new Shell();
            Folder directory = shell.NameSpace(dirName);
            FolderItem folderItem = directory.ParseName(Path.GetFileName(path));

            Dictionary<int, string> headers = GetExtendedPropertyHeaders(directory);

            if (folderItem != null)
            {
                properties = new Dictionary<string, string>();
                for (int i = 0; i < EXTENDED_HEADER_COUNT + 1; i++)
                {
                    string property = directory.GetDetailsOf(folderItem, i);
                    if (!string.IsNullOrEmpty(property))
                    {
                        properties.Add(headers[i], property);
                    }
                }
            }

            return properties;
        }
예제 #5
0
        public static List<SelectedItem> GetSelectedItems(IntPtr windowHandle)
        {
            var results = new List<SelectedItem>();

            IntPtr handle = WinApi.GetForegroundWindow();

            if (handle == progmanHandle || handle == windowHandle)
            {
                Logger.Debug("Desktop listview is active", LogSource.Interop);

                // Desktop has focus
                foreach (var file in GetSelectedItemsOnDesktop())
                    results.Add(file);
            }
            else
            {
                Logger.Debug("Desktop listview was not active, expected handle for desktop {0} or for window {1}, actual handle {2}", LogSource.Interop, progmanHandle, windowHandle, handle);

                // Other window, try to determine if is a shell window
                Shell shell = new Shell();
                ShellWindows windows = (ShellWindows)shell.Windows();

                foreach (InternetExplorer window in windows)
                {
                    string processName = Path.GetFileNameWithoutExtension(window.FullName).ToLower();

                    if (processName.Equals("iexplore"))
                    {
                        if ((int)handle == window.HWND)
                        {
                            Logger.Debug("Active window was internet explorer instance {0}", LogSource.Interop, handle);
                            Logger.Debug("   Adding {0}", LogSource.Interop, window.LocationURL);

                            results.Add(new BrowserSelectedUrl() { Url = window.LocationURL });
                        }
                    }

                    else if (processName.Equals("explorer"))
                    {
                        if ((int)handle == window.HWND)
                        {
                            Logger.Debug("Active window was windows explorer instance {0}", LogSource.Interop, handle);

                            ShellFolderView view = (ShellFolderView)window.Document;
                            FolderItems items = view.SelectedItems();

                            foreach (FolderItem item in items)
                            {
                                Logger.Debug("   Adding path {0}", LogSource.Interop, item.Path);

                                results.Add(new ExplorerSelectedFile() { Location = Path.GetDirectoryName(item.Path), Filename = Path.GetFileName(item.Path) });
                            }
                        }
                    }
                }
            }

            return results;
        }
 void IInitializeWithFile.Initialize(string filePath, Shell.AccessModes fileMode)
 {
     IPreviewFromFile preview = this as IPreviewFromFile;
     if (preview == null)
     {
         throw new InvalidOperationException(
             string.Format(System.Globalization.CultureInfo.InvariantCulture,
             LocalizedMessages.PreviewHandlerUnsupportedInterfaceCalled,
             "IPreviewFromFile"));
     }
     preview.Load(new FileInfo(filePath));
 }
예제 #7
0
        public static string ExtractZipFile(string sourceFile, string destinationFolder)
        {
            Shell objShell = new Shell();
            Folder destination = objShell.NameSpace(destinationFolder);
            Folder source = objShell.NameSpace(sourceFile);

            foreach (var file in source.Items())
            {
                destination.CopyHere(file, 4 | 16);
            }
            return destinationFolder;
        }
예제 #8
0
        public BackgroundJobManager(Shell.Infrastructure.Logging.ILogger logger, IScheduler sched)
        {
            _jobs = new Jobs();
            _logger = logger;
            _scheduler = sched;

            if (!_scheduler.IsStarted)
            {
                _scheduler.Start();
                _scheduler.AddGlobalJobListener(new QueueUpdateManager());
                QuartzNetWebConsole.Setup.Scheduler = () => _scheduler;
                QuartzNetWebConsole.Setup.Logger = new MemoryLogger(10000);
            }
        }
예제 #9
0
        public static TimeSpan FindLength( string location, int index )
        {
            try {

                Shell shell = new Shell ();
                var dr = shell.NameSpace ( location );
                var itm = dr.ParseName ( Path.GetFileName ( location ) );

                var prop = dr.GetDetailsOf ( itm, index );

                return TimeSpan.Parse ( prop );

            } catch {
                return new TimeSpan ();
            }
        }
예제 #10
0
 public void StopTest()
 {
     Session session = null; // TODO: Initialize to an appropriate value
     Stream input = null; // TODO: Initialize to an appropriate value
     Stream output = null; // TODO: Initialize to an appropriate value
     Stream extendedOutput = null; // TODO: Initialize to an appropriate value
     string terminalName = string.Empty; // TODO: Initialize to an appropriate value
     uint columns = 0; // TODO: Initialize to an appropriate value
     uint rows = 0; // TODO: Initialize to an appropriate value
     uint width = 0; // TODO: Initialize to an appropriate value
     uint height = 0; // TODO: Initialize to an appropriate value
     IDictionary<TerminalModes, uint> terminalModes = null; // TODO: Initialize to an appropriate value
     int bufferSize = 0; // TODO: Initialize to an appropriate value
     Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value
     target.Stop();
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
예제 #11
0
        public string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

            Shell32.Shell shell = new Shell();
            Shell32.Folder folder = shell.NameSpace(pathOnly);
            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);

            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                return link.Path;
            }

            return string.Empty;
        }
예제 #12
0
        public static Dictionary<int, string> GetExtendedPropertyHeaders(string path)
        {
            Dictionary<int, string> headers = null;

            var dirName = Path.GetDirectoryName(path);
            if (!Directory.Exists(dirName))
            {
                return headers;
            }

            Shell shell = new Shell();
            Folder directory = shell.NameSpace(dirName);

            headers = GetExtendedPropertyHeaders(directory);

            return headers;
        }
        static int GetDuration(string filename)
        {
            int duration = 0;
            try
            {
                var shl = new Shell();
                var fldr = shl.NameSpace(Path.GetDirectoryName(filename));
                var itm = fldr.ParseName(Path.GetFileName(filename));

                // Index 27 is the video duration [This may not always be the case]
                var propValue = fldr.GetDetailsOf(itm, 285);
                duration = Convert.ToInt32(propValue);
                //return duration;
                //return TimeSpan.TryParse(propValue, out duration);
            }
            catch (Exception)
            {
                //Console.WriteLine("Problem 1");
            }
            return duration;
        }
예제 #14
0
        public void TestPiping()
        {
            var shell = new Shell(o => o.ThrowOnError());

            var kinds = Enum.GetValues(typeof(Kind)).Cast<Kind>();
            foreach (var inKind in kinds)
            {
                foreach (var outKind in kinds.Where(k => k != Kind.String))
                {
                    dynamic input = this.CreateSinkOrSource(inKind, isOut: false);
                    dynamic output = this.CreateSinkOrSource(outKind, isOut: true);
                    var command = shell.Run("SampleCommand", "echo");
                    var tasks = new List<Task>();
                    if (input is TextReader)
                    {
                        tasks.Add(command.StandardInput.PipeFromAsync((TextReader)input));
                    }
                    else
                    {
                        command = command < input;
                    }
                    if (output is TextWriter)
                    {
                        tasks.Add(command.StandardOutput.PipeToAsync((TextWriter)output));
                    }
                    else
                    {
                        command = command > output;
                    }
                    tasks.Add(command.Task);
                    Task.WaitAll(tasks.ToArray());

                    string result = this.Read(outKind, output);
                    // MA: the output changes slightly if we are inputting as lines (adds a newline) and not outputting as lines
                    result.ShouldEqual(Content + (inKind == Kind.Lines && outKind != Kind.Lines ? Environment.NewLine : string.Empty), inKind + " => " + outKind);
                }
            }
        }
 public VideoMetadataProvider()
 {
     this._scheduler = new SingleThreadTaskScheduler(() => this._shell = new Shell());
 }
 void IInitializeWithItem.Initialize(IShellItem shellItem, Shell.AccessModes accessMode)
 {
     IPreviewFromShellObject preview = this as IPreviewFromShellObject;
     if (preview == null)
     {
         throw new InvalidOperationException(
             string.Format(System.Globalization.CultureInfo.InvariantCulture,
             LocalizedMessages.PreviewHandlerUnsupportedInterfaceCalled,
             "IPreviewFromShellObject"));
     }
     using (var shellObject = Shell.ShellObjectFactory.Create(shellItem))
     {
         preview.Load(shellObject);
     }
 }
예제 #17
0
        public LoadConfigCommand(Shell.IMAPShell shell, string[] args)
            : base(shell, "loadconfig", args)
        {

        }
 void IInitializeWithStream.Initialize(System.Runtime.InteropServices.ComTypes.IStream stream, Shell.AccessModes fileMode)
 {
     IPreviewFromStream preview = this as IPreviewFromStream;
     if (preview == null)
     {
         throw new InvalidOperationException(
             string.Format(System.Globalization.CultureInfo.InvariantCulture,
             LocalizedMessages.PreviewHandlerUnsupportedInterfaceCalled,
             "IPreviewFromStream"));
     }
     using (var storageStream = new StorageStream(stream, fileMode != Shell.AccessModes.ReadWrite))
     {
         preview.Load(storageStream);
     }
 }
예제 #19
0
        public void UnZip(string zipFile, string folderPath)
        {
            int extractedFiles = 9;
            int totalFiles = 0;
            string filename = Path.GetFileName(zipFile);

            if (!File.Exists(zipFile))
                throw new FileNotFoundException();

            if (!Directory.Exists(folderPath))
                Directory.CreateDirectory(folderPath);

            Shell objShell = new Shell();
            Folder destinationFolder = objShell.NameSpace(folderPath);
            Folder sourceFile = objShell.NameSpace(zipFile);

            // TODO: this doesn't actually get the number of files in the archive
            // just the number of items it sees at the top level of the archive
            // including folders
            totalFiles = sourceFile.Items().Count;

            if (StartedUnzip != null)
                StartedUnzip(this, new StartUnzipEventArgs(filename, 0, totalFiles));

            foreach (var file in sourceFile.Items())
            {
                destinationFolder.CopyHere(file, 16);
                extractedFiles++;

                // useless unless we use a different method of unzipping.
                // Shell32 extracts the file in one big step and never gives
                // us the opportunity to report progress or update the form
                // from here

                //if (ProgressedUnzip != null)
                //    ProgressedUnzip(this, new ProgressUnzipEventArgs("extractedfilenamehere", extractedFiles, totalFiles));
            }

            if (EndedUnzip != null)
                EndedUnzip(this, new EndUnzipEventArgs(zipFile, 0));
        }
예제 #20
0
        /// <summary>
        /// Checks wheter if the shortcut is created.
        /// </summary>
        /// <returns></returns>
        public static bool IsStartupCreated() //If there is a shortcut called WallpaperClock and it's target is current directory.
        {
            Shell shell = new Shell();

            if (File.Exists(startupPath + "\\WallpaperClock.lnk"))
            {
                Folder folder = shell.NameSpace(startupPath);
                FolderItem folderItem = folder.ParseName("WallpaperClock.lnk");
                Shell32.ShellLinkObject link = folderItem.GetLink as Shell32.ShellLinkObject;


                if (string.Equals(link.Path, currentPath, StringComparison.OrdinalIgnoreCase)) //If the current shortcut's target equals current .exe's location.
                    return true;

            }
            return false;
        }
예제 #21
0
파일: Image.cs 프로젝트: Eygle/wmp
 Dictionary<int, KeyValuePair<string, string>> GetFileProps(string filename)
 {
     Shell shl = new Shell();
     Folder fldr = shl.NameSpace(Path.GetDirectoryName(filename));
     FolderItem itm = fldr.ParseName(Path.GetFileName(filename));
     Dictionary<int, KeyValuePair<string, string>> fileProps = new Dictionary<int, KeyValuePair<string, string>>();
     for (int i = 0; i < 100; i++)
     {
         string propValue = fldr.GetDetailsOf(itm, i);
         if (propValue != "")
         {
             fileProps.Add(i, new KeyValuePair<string, string>(fldr.GetDetailsOf(null, i), propValue));
         }
     }
     return fileProps;
 }
예제 #22
0
 void IInitializeWithItem.Initialize(Shell.IShellItem shellItem, Shell.AccessModes accessMode)
 {
     _shellObject = ShellObjectFactory.Create(shellItem);
 }
예제 #23
0
 void IInitializeWithStream.Initialize(System.Runtime.InteropServices.ComTypes.IStream stream, Shell.AccessModes fileMode)
 {
     _stream = new StorageStream(stream, fileMode != Shell.AccessModes.ReadWrite);
 }
예제 #24
0
파일: ExtractZip.cs 프로젝트: zhangjinde/se
 public void ExtractFilesFromZip(string src, string dest)
 {
     Shell sh = new Shell();
     Folder inzip = sh.NameSpace(src);
     Folder outdir = sh.NameSpace(dest);
     outdir.CopyHere(inzip.Items(), 0);  // 4 for no progress dialog, 16 for Yes to all
 }
예제 #25
0
        private static SongDbItems GetSongInfo(string filepath)
        {
            SongDbItems songInfo = new SongDbItems();
            songInfo.path = filepath;
            Shell shell = new Shell();
            string filedir = Path.GetDirectoryName(filepath);
            string filename = Path.GetFileName(filepath);
            Folder objFolder = shell.NameSpace(filedir);
            if (objFolder != null)
            {
                FolderItem fi = objFolder.ParseName(filename);
                songInfo.name = objFolder.GetDetailsOf(fi, 21);
                songInfo.album = objFolder.GetDetailsOf(fi, 14);
                songInfo.artist = objFolder.GetDetailsOf(fi, 20);
                string year_string = objFolder.GetDetailsOf(fi, 15);
                if (!String.IsNullOrEmpty(year_string))
                {
                    songInfo.year = int.Parse(year_string);
                }
                else
                {
                    songInfo.year = 0;
                }
                if (songInfo.name.Contains("'"))
                {
                    songInfo.name = songInfo.name.Replace("'", "`");
                }
                if (songInfo.album.Contains("'"))
                {
                    songInfo.album = songInfo.album.Replace("'", "`");
                }
                if (songInfo.artist.Contains("'"))
                {
                    songInfo.artist = songInfo.artist.Replace("'", "`");
                }
                if (songInfo.path.Contains("'"))
                {
                    songInfo.path = songInfo.path.Replace("'", "`");
                }
            }

            return songInfo;
        }
예제 #26
0
        private static List<Shell> Shoot(List<Shell> shells, int shipX, int shipY, char shellDesign, ConsoleColor color, bool goingUp = true)
        {
            Shell currentShell = new Shell();

            currentShell.x = shipX;
            currentShell.y = shipY;
            currentShell.shellDesign = shellDesign;
            currentShell.color = color;
            currentShell.goingUp = goingUp;

            //when we shoot we take the coordinates of the ship and add the shots into the list with all the shots
            shells.Add(currentShell);

            return shells;
        }
예제 #27
0
        /// <summary>
        /// 日本語名称取得
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private string GetJpnName(string path)
        {
            var dirNm = Path.GetDirectoryName(path);
            var fileNm = Path.GetFileName(path);

            var shell = new Shell();
            var f = shell.NameSpace(dirNm);
            var item = f.ParseName(fileNm);
            return item.Name;
        }
예제 #28
0
        // Move the shells upward/downward
        static List<Shell> UpdateShells(List<Shell> shells)
        {
            // init the needed variables
            List<Shell> movedShells = new List<Shell>(shells.Count);
            Shell currentShell = new Shell();

            // move each shell upwards/downwards
            for (int i = 0; i < shells.Count; i++)
            {
                // if the shell has reached the end of the screen, skip this loop
                if (shells[i].y == 0 || shells[i].y == Console.BufferHeight)
                {
                    continue;
                }

                // add the appropriate values
                currentShell.shellDesign = shells[i].shellDesign;
                currentShell.color = shells[i].color;
                currentShell.x = shells[i].x;
                currentShell.goingUp = shells[i].goingUp;

                // move the shell up/down
                if (currentShell.goingUp)
                {
                    // move the shell up
                    currentShell.y = shells[i].y - 1;
                }
                else
                {
                    // move the shell down
                    currentShell.y = shells[i].y + 1;
                }

                // add the current shell to the new list of moved shells
                movedShells.Add(currentShell);
            }

            // return the new list
            return movedShells;
        }
예제 #29
0
        private static bool isPlayerShipHitEnemy( List<Shell> shells,List<Spaceship> enemyShips)
        {
            bool IsEnemyHit = false;
            for (int j = 0; j < enemyShips.Count; j++)
            {
                Shell currentShell = new Shell();
                Spaceship enemyShip = enemyShips[j];
                string[] EnemySpaceshipLines = enemyShip.spaceshipDesign.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

                int playerHight = EnemySpaceshipLines.GetLength(0);
                int playerWidth = EnemySpaceshipLines[1].Length;

                for (int i = 0; i < shells.Count; i++)
                {
                    currentShell = shells[i];
                    if (currentShell.y >= enemyShip.y && currentShell.y <= enemyShip.y + playerHight - 1
                        && currentShell.x >= enemyShip.x && currentShell.x <= enemyShip.x + playerWidth - 1)
                    {

                        if (EnemySpaceshipLines[currentShell.y - enemyShip.y][currentShell.x - enemyShip.x] != ' ')
                        {
                            IsEnemyHit = true;
                            enemyShips.Remove(enemyShip);// премахваме вражеският кораб от списъка с кораби
                            foreach (var line in EnemySpaceshipLines)
                            {
                                enemyShip.spaceshipDesign = "  ";
                            }

                            UpdateScreen(); //  би трябвало екрана да се обнови след като се "изтрие" ударения кораб
                            return IsEnemyHit;
                        }
                    }
                }
            }
            return IsEnemyHit;
        }
예제 #30
0
 void IInitializeWithFile.Initialize(string filePath, Shell.AccessModes fileMode)
 {
     _info = new FileInfo(filePath);
 }