Exemplo n.º 1
0
////        private bool _IconResourceIdInitialized;
////        private string _IconResourceId;
////
////        private bool _KnownFolderIsInitialized;
////        private bool _ItemTypeIsInitialized;
        #endregion fields

        #region ctors
        /// <summary>
        /// constructor to initialize only <see cref="Path_RAW"/> and
        /// <see cref="PathFileSystem"/> property or
        /// <see cref="PathSpecialItemId"/> property.
        /// <paramref name="rawPath"/> can be either a real path
        /// or special folder path starting with '::{...}'
        /// </summary>
        /// <param name="rawPath"></param>
        /// <param name="parsingName"></param>
////        /// <param name="itemType"></param>
        protected BrowseItemFromPath(string rawPath,
                                     string parsingName
////                                      ,DirectoryItemFlags itemType = DirectoryItemFlags.Unknown
                                     )
        {
            Path_RAW = rawPath;

            var pathType = ShellHelpers.IsSpecialPath(parsingName);

            if (pathType == ShellHelpers.SpecialPath.None)
            {
                PathFileSystem = parsingName;
            }
            else
            {
                if (pathType == ShellHelpers.SpecialPath.IsSpecialPath ||
                    pathType == ShellHelpers.SpecialPath.ContainsSpecialPath)
                {
                    IsSpecialParseItem = true;
                    PathSpecialItemId  = parsingName;
                }
            }

////            if (itemType != DirectoryItemFlags.Unknown)
////            {
////                ItemType = itemType;
////                _ItemTypeIsInitialized = true;
////            }
        }
Exemplo n.º 2
0
 private void Checkout(Uri svnUri, SvnChangeset set, string workPath)
 {
     using (SvnClient svn = new SvnClient())
     {
         if (Directory.Exists(workPath))
         {
             try
             {
                 svn.Switch(workPath, new SvnUriTarget(svnUri, set.Revision));
             }
             catch (SvnFileSystemException)
             {
                 // this seems to happen when you try to switch to a branch
                 // without any file changes - revision 814 in Cyotek triggers this
                 // in this case, we do a full checkout which seems to succeed fine
                 ShellHelpers.DeletePath(workPath);
                 this.FullCheckout(svn, svnUri, set, workPath);
             }
         }
         else
         {
             this.FullCheckout(svn, svnUri, set, workPath);
         }
     }
 }
Exemplo n.º 3
0
 public static string ConfigGet(string key)
 {
     try {
         return(ShellHelpers.OutputFromCommand("git", "config --get " + key));
     } catch {
         _isWorking = false;
         return(null);
     }
 }
Exemplo n.º 4
0
 public static string GetDiff(string path, bool wordDiff)
 {
     try {
         string diffParams = wordDiff ? "--word-diff=porcelain " : "";
         return(ShellHelpers.OutputFromCommand("git", "diff --submodule=log " + diffParams + "-- " + QuotePath(path)));
     } catch {
         _isWorking = false;
         return(null);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Converts a path representation 'C:\' into an
        /// <see cref="IntPtr"/> formated PIDL representation.
        ///
        /// The memory of the PIDL returned must be freed with
        /// <see cref="Marshal.FreeCoTaskMem"/> by the caller.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static IntPtr GetPIDLFromPath(string path)
        {
            if (string.IsNullOrEmpty(path) == true)
            {
                return(IntPtr.Zero);
            }

            IntPtr pidlPtr = default(IntPtr);

            // Handle Special Folder path notation
            if (ShellHelpers.IsSpecialPath(path) == ShellHelpers.SpecialPath.IsSpecialPath)
            {
                if (HasNoPIDL(path) == true)
                {
                    return(IntPtr.Zero);
                }

                using (var kf = KnownFolderHelper.FromPath(path))
                {
                    if (kf != null)
                    {
                        try
                        {
                            kf.Obj.GetIDList((uint)KNOWN_FOLDER_FLAG.KF_NO_FLAGS, out pidlPtr);
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("ArgumentException '{0}'", path);
                            return(IntPtr.Zero);
                        }

                        return(pidlPtr);
                    }
                }
            }

            using (var desktopFolder = new ShellFolderDesktop())
            {
                SFGAO pdwAttributes = 0;
                uint  pchEaten      = 0;

                if (desktopFolder.Obj.ParseDisplayName(IntPtr.Zero, IntPtr.Zero,
                                                       path, ref pchEaten, out pidlPtr,
                                                       ref pdwAttributes) == (uint)HRESULT.S_OK)
                {
                    return(pidlPtr);
                }
            }

            return(IntPtr.Zero);
        }
        private void _Drop(object sender, DragEventArgs e)
        {
            // Create a IShellItemArray from the IDataObject
            // For this sample, we only open the first item that was dragged and dropped to our application.
            var psi = ShellHelpers.GetDragItem(e.Data);

            if (psi != null)
            {
                // Get the full path of the file
                string pszPath = psi.GetDisplayName(SIGDN.SIGDN_FILESYSPATH);
                // Open the file
                _OpenFile(pszPath);
            }
        }
Exemplo n.º 7
0
        public void GetPidlForDirectoryPath()
        {
            // Get the default drive's path
            var drive = new DirectoryInfo(Environment.SystemDirectory).Root.Name;

            Assert.IsFalse(string.IsNullOrEmpty(drive));

            // enumerate on root directores of the default drive and
            // verify correct pidl <-> path reprentation for each directory
            foreach (var originalPath in Directory.EnumerateDirectories(drive))
            {
                IntPtr pidl = default(IntPtr);
                try
                {
                    pidl = PidlManager.GetPIDLFromPath(originalPath);

                    Assert.IsFalse(pidl == default(IntPtr));

                    string logicalPath   = PidlManager.GetPathFromPIDL(pidl);
                    string physStorePath = PidlManager.GetPathFromPIDL(pidl, TypOfPath.PhysicalStoragePath);

                    // The logical path of a special path '::{...}' will differ from
                    // its physical representation 'C:\Windows'
                    // Otherwise, both repesentations should be equal for non-special folders
                    if (ShellHelpers.IsSpecialPath(logicalPath) == ShellHelpers.SpecialPath.IsSpecialPath)
                    {
                        Assert.IsFalse(string.Equals(logicalPath, physStorePath));
                    }
                    else
                    {
                        Assert.IsTrue(string.Equals(logicalPath, physStorePath));
                    }

                    ////Console.WriteLine("Path Retrieval via PIDL: '{0}' -> Logical Path: '{1}', Physical Path: '{2}'",
                    ////    originalPath, logicalPath, physStorePath);
                }
                finally
                {
                    pidl = PidlManager.ILFree(pidl);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Class constructor from strings that are commonly exposed by
        /// <see cref="IShellFolder2"/> interfaces. Constructing from these
        /// items can speed up enumeration since we do not need to revisit
        /// each items <see cref="IShellFolder2"/> interfaces.
        /// </summary>
        /// <param name="parseName"></param>
        /// <param name="name"></param>
        /// <param name="labelName"></param>
        /// <returns></returns>
        internal static BrowseItemFromPath InitItem(string parseName,
                                                    string name,
                                                    string labelName)
        {
////            bool hasPIDL = false;
////            IdList parentIdList = null;
////            IdList relativeChildIdList = null;

            string path = parseName;
            string normPath = null, SpecialPathId = null;

            ShellHelpers.SpecialPath isSpecialID = ShellHelpers.IsSpecialPath(path);
            if (isSpecialID == ShellHelpers.SpecialPath.None)
            {
                normPath = parseName;
            }
            else
            {
                SpecialPathId = path;
            }

////            hasPIDL = PidlManager.GetParentIdListFromPath(path, out parentIdList, out relativeChildIdList);
////            if (hasPIDL == false)   // return references that cannot resolve with a PIDL
////            {
////                var ret = new BrowseItemFromPath2(path, path);
////                ret.Name = path;
////                return ret;
////            }

////            IdList fullIdList = null;
////
////            // Get the IShellFolder2 Interface for the original path item...
////            // We are asked to build the desktop root item here...
////            if ((parentIdList == null && relativeChildIdList == null) == false)
////                fullIdList = PidlManager.CombineParentChild(parentIdList, relativeChildIdList);

            return(new BrowseItemFromPath(path, parseName, name, labelName,
                                          SpecialPathId, normPath
////                                           ,parentIdList, relativeChildIdList
                                          ));
        }
Exemplo n.º 9
0
        public override void Execute(object parameter)
        {
            string path = parameter.CheckAs <string>();

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (Factory.Resolve <Settings>().PreviewItems)
            {
                try
                {
                    if (File.Exists(path) && new FileInfo(path).Length < 1024 * 1024)
                    {
                        ShellHelpers.OpenFileInPreviewTab(path);
                    }
                }
                catch
                {
                    // nothing to do here if this fails
                }
            }
        }
Exemplo n.º 10
0
        private void _DragEnter(object sender, DragEventArgs e)
        {
            var psi = ShellHelpers.GetDragItem(e.Data);

            e.Effect = psi == null ? DragDropEffects.None : DragDropEffects.Link;
        }
Exemplo n.º 11
0
////        public void LoadProperties()
////        {
////            if (_KnownFolderIsInitialized == false)
////            {
////                _KnownFolderIsInitialized = true;
////                KnownFolder = LoadKnownFolder();
////            }
////
////            if (_ItemTypeIsInitialized == false)
////            {
////                _ItemTypeIsInitialized = true;
////                ItemType = LoadItemType();
////            }
////
////            if (_IconResourceIdInitialized == false)
////            {
////                _IconResourceIdInitialized = true;
////                _IconResourceId = LoadIconResourceId();
////            }
////        }

        /// <summary>
        /// Initializes the items type flags and path properties.
        /// </summary>
        /// <param name="path">Is either a path reference a la 'C:' or a
        /// special folder path reference a la '::{...}' <seealso cref="KF_IID"/>
        /// for more details.</param>
        /// <returns>Returns a simple pojo type object to initialize
        /// the calling object members.</returns>
        internal static BrowseItemFromPath InitItem(string path)
        {
            if (string.IsNullOrEmpty(path) == true)   // return unknown references
            {
                var ret = new BrowseItemFromPath(path, path);
                ret.Name = path;
                return(ret);
            }

            if (path.Length == 38)
            {
                try
                {
                    Guid theGuid;
                    if (Guid.TryParse(path, out theGuid) == true)
                    {
                        path = KF_IID.IID_Prefix + path;
                    }
                }
                catch
                {
                    // Catching errors just in case ...
                }
            }

            // Return item for root desktop item
            if (string.Compare(path, KF_IID.ID_ROOT_Desktop, true) == 0)
            {
                return(InitDesktopRootItem());
            }

            ShellHelpers.SpecialPath isSpecialID = ShellHelpers.IsSpecialPath(path);
            string normPath = null, SpecialPathId = null;
            bool   hasPIDL = false;
            IdList parentIdList, relativeChildIdList;

            if (isSpecialID == ShellHelpers.SpecialPath.IsSpecialPath)
            {
                SpecialPathId = path;
                hasPIDL       = PidlManager.GetParentIdListFromPath(path, out parentIdList, out relativeChildIdList);
            }
            else
            {
                normPath = Browser.NormalizePath(path);
                hasPIDL  = PidlManager.GetParentIdListFromPath(normPath, out parentIdList, out relativeChildIdList);
            }

            if (hasPIDL == false)   // return references that cannot resolve with a PIDL
            {
                var ret = new BrowseItemFromPath(path, path);
                ret.Name = path;
                return(ret);
            }

            string parseName      = normPath;
            string name           = normPath;
            string labelName      = null;
            IdList fullIdList     = null;

            // Get the IShellFolder2 Interface for the original path item...
            IntPtr fullPidlPtr    = default(IntPtr);
            IntPtr ptrShellFolder = default(IntPtr);
            IntPtr parentPIDLPtr  = default(IntPtr);
            IntPtr relativeChildPIDLPtr = default(IntPtr);

            try
            {
                // We are asked to build the desktop root item here...
                if (parentIdList == null && relativeChildIdList == null)
                {
                    using (var shellFolder = new ShellFolderDesktop())
                    {
                        parseName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_FORPARSING);
                        name      = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_INFOLDER | SHGDNF.SHGDN_FOREDITING);
                        labelName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_NORMAL);
                    }
                }
                else
                {
                    fullIdList  = PidlManager.CombineParentChild(parentIdList, relativeChildIdList);
                    fullPidlPtr = PidlManager.IdListToPidl(fullIdList);

                    if (fullPidlPtr == default(IntPtr))
                    {
                        return(null);
                    }

                    HRESULT hr = HRESULT.False;

                    if (fullIdList.Size == 1) // Is this item directly under the desktop root?
                    {
                        hr = NativeMethods.SHGetDesktopFolder(out ptrShellFolder);

                        if (hr != HRESULT.S_OK)
                        {
                            return(null);
                        }

                        using (var shellFolder = new ShellFolder(ptrShellFolder))
                        {
                            parseName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_FORPARSING);
                            name      = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_INFOLDER | SHGDNF.SHGDN_FOREDITING);
                            labelName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_NORMAL);
                        }
                    }
                    else
                    {
                        parentPIDLPtr        = PidlManager.IdListToPidl(parentIdList);
                        relativeChildPIDLPtr = PidlManager.IdListToPidl(relativeChildIdList);

                        using (var desktopFolder = new ShellFolderDesktop())
                        {
                            hr = desktopFolder.Obj.BindToObject(parentPIDLPtr, IntPtr.Zero,
                                                                typeof(IShellFolder2).GUID, out ptrShellFolder);
                        }

                        if (hr != HRESULT.S_OK)
                        {
                            return(null);
                        }

                        // This item is not directly under the Desktop root
                        using (var shellFolder = new ShellFolder(ptrShellFolder))
                        {
                            parseName = shellFolder.GetShellFolderName(relativeChildPIDLPtr, SHGDNF.SHGDN_FORPARSING);
                            name      = shellFolder.GetShellFolderName(relativeChildPIDLPtr, SHGDNF.SHGDN_INFOLDER | SHGDNF.SHGDN_FOREDITING);
                            labelName = shellFolder.GetShellFolderName(relativeChildPIDLPtr, SHGDNF.SHGDN_NORMAL);
                        }
                    }
                }

                if (ShellHelpers.IsSpecialPath(parseName) == ShellHelpers.SpecialPath.None)
                {
                    normPath = parseName;
                }

                return(new BrowseItemFromPath(path, parseName, name, labelName,
                                              SpecialPathId, normPath
////                                               ,parentIdList, relativeChildIdList
                                              ));
            }
            finally
            {
                PidlManager.ILFree(parentPIDLPtr);
                PidlManager.ILFree(relativeChildPIDLPtr);

                if (fullPidlPtr != default(IntPtr))
                {
                    NativeMethods.ILFree(fullPidlPtr);
                }
            }
        }
Exemplo n.º 12
0
 internal static extern void PropVariantClear(ref ShellHelpers.PROPVARIANT pvar);
Exemplo n.º 13
0
 public static void StagePath(string path)
 {
     ShellHelpers.OutputFromCommand("git", "add --ignore-errors -- " + QuotePath(path));
 }
Exemplo n.º 14
0
 public static void LaunchGitGui()
 {
     ShellHelpers.StartProcess("git", "gui");
 }
Exemplo n.º 15
0
 public static void LaunchGitk()
 {
     ShellHelpers.StartProcess("gitk", "--all");
 }
Exemplo n.º 16
0
        private void MigrateBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MigrationOptions options;
            Uri svnUri;
            SvnChangesetCollection sets;
            string           workPath;
            string           gitPath;
            StringCollection includes;
            StringCollection excludes;

            options  = (MigrationOptions)e.Argument;
            svnUri   = options.SvnUri;
            workPath = options.WorkingPath;
            gitPath  = options.RepositoryPath;
            includes = this.GetGlobs(includesTextBox);
            excludes = this.GetGlobs(excludesTextBox);

            sets = options.Revisions;

            this.CreateGitRepository(gitPath);

            for (int i = 0; i < sets.Count; i++)
            {
                SvnChangeset  set;
                int           progress;
                ProgressState args;

                set      = sets[i];
                progress = Convert.ToInt32((double)i / sets.Count * 100);

                args = new ProgressState
                {
                    Total     = sets.Count,
                    Current   = i + 1,
                    Changeset = set
                };

                if (string.IsNullOrEmpty(set.Author.EmailAddress))
                {
                    set.Author = options.Authors.GetMapping(set.Author.Name);
                }

                if (this.ShouldCheckout(set, includes, excludes))
                {
                    migrateBackgroundWorker.ReportProgress(progress, args);

                    this.Checkout(svnUri, set, workPath);
                    SimpleFolderSync.SyncFolders(workPath, gitPath, includes, excludes);

                    try
                    {
                        this.Commit(gitPath, set);
                    }
                    catch (EmptyCommitException)
                    {
                        // ignore, if we get this the user has
                        // disabled the option to allow empty commits
                    }
                }
                else
                {
                    args.Changeset = null;
                    migrateBackgroundWorker.ReportProgress(progress, args);
                }

                if (migrateBackgroundWorker.CancellationPending)
                {
                    throw new ApplicationException("User cancelled operation.");
                }
            }

            ShellHelpers.DeletePath(workPath);
        }
Exemplo n.º 17
0
 public static void RemovePath(string path)
 {
     ShellHelpers.OutputFromCommand("git", "rm -- " + QuotePath(path));
 }
Exemplo n.º 18
0
 public static void UnstagePath(string path)
 {
     ShellHelpers.OutputFromCommand("git", "reset HEAD -- " + QuotePath(path));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Returns a known folder given its shell path, such as <c>C:\users\public\documents</c> or
        /// <c>::{645FF040-5081-101B-9F08-00AA002F954E}</c> for the Recycle Bin.
        /// </summary>
        /// <param name="path">The path for the requested known folder; either a physical path or a virtual path.</param>
        /// <param name="IsSpecialPath"></param>
        /// <returns>A known folder representing the specified name.</returns>
        public static KnownFolderNative FromPath(string path, bool?IsSpecialPath)
        {
            if (string.IsNullOrEmpty(path) == true)
            {
                throw new ArgumentNullException("'path' parameter cannot be Empty or Null.");
            }

            if (IsSpecialPath == null)
            {
                IsSpecialPath = (ShellHelpers.IsSpecialPath(path) == ShellHelpers.SpecialPath.IsSpecialPath);
            }

            if (IsSpecialPath == true)
            {
                // Get the KnownFolderId Guid for this special folder
                var kf_guid = new Guid(path.Substring(KF_IID.IID_Prefix.Length));

                try
                {
                    var ret = FromKnownFolderGuid(kf_guid);

                    if (ret != null)
                    {
                        return(ret);
                    }
                }
                catch
                {
                    // continue iteration on exceptional errors
                }
            }

            IntPtr pidl = default(IntPtr);

            try
            {
                pidl = ShellHelpers.PIDLFromPath(path);

                if (pidl == default(IntPtr))
                {
                    // try one more time with a trailing \0
                    pidl = ShellHelpers.PidlFromParsingName(path);
                }

                if (pidl != default(IntPtr))
                {
                    // It's probably a special folder, try to get it
                    var kf = KnownFolderHelper.FromPIDL(pidl);

                    if (kf != null)
                    {
                        return(kf);
                    }
                }
            }
            finally
            {
                pidl = PidlManager.ILFree(pidl);
            }

            return(null);
        }