blog: riddles in programming

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

User avatar
nikos
Site Admin
Site Admin
Posts: 14484
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

blog: riddles in programming

Post by nikos » 2007 Jul 08, 08:46

here's the comment area for today's blog entry found at:
http://www.zabkat.com/blog/08Jul07.htm

User avatar
fgagnon
Site Admin
Site Admin
Posts: 3737
Joined: 2003 Sep 08, 19:56
Location: Springfield

Post by fgagnon » 2007 Jul 08, 13:22

Straightforward, once you found enough of the puzzle pieces ---
even clever in spots.  But, it's too bad that it took so much work slogging through the m$ morass to cobble together a solution.  

So, I say, Good work, Sherlock!

(Yet, as satisfying as that was, I am sure you would have preferred to find a more elegant solution.)

wasker
Gold Member
Gold Member
Posts: 797
Joined: 2005 Oct 21, 16:33
Location: WA, USA
Contact:

Post by wasker » 2007 Jul 08, 16:32

Oh boy... :shock: You da man! :beer:
I'm using Xplorer2 - the only file manager that does not suck. Actually, it rocks!

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 13, 04:48

Hi nikos,

 I have been struggling with this a bit.  I actually was overriding the IShellFolder and returning my own IDataObject last year but I was missing the registry key piece of it.  I have it all working... sort of.  Are you 100% successful now? My problem is that when I call release on the Context menu that CDefFolderMenu_Create2 give me if I have too many keys in the key list it crashes RegCloseKey from within the release call of the IContextMenu object.  I have not yet closed the keys before doing this so it is not from double closing them.  I can't quite tell you exactly where the issue is.  If it is greater then 5 or 7 registry key or if it is after 500 files with > 5 keys.  I can get to a point where if I add just one more file to the list it will crash and if I remove that file from the list it will succeed.

Just wondering if you were having any strange issues such as this.

Jim Kueneman

P.S.  It is not that my IShellFolder wrapper is being prematurely released I have checked all my reference counted objects during this and non of them are being freed before during or after the crash on the ContextMenu release occurs.

User avatar
fgagnon
Site Admin
Site Admin
Posts: 3737
Joined: 2003 Sep 08, 19:56
Location: Springfield

Post by fgagnon » 2007 Aug 13, 12:30

Hi Jim,

Welcome to the board!

nikos is on vacation until the end of August.
(He may only check in at random until then.)

Your query sounds like it is a program development issue, rather than xplorer2-related.
Although you might get a constructive reply from nikos or our readers, you are likely to get more help sooner from the users at The Code Project: http://www.codeproject.com/  

-fg-
Last edited by fgagnon on 2007 Aug 13, 13:08, edited 1 time in total.

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 13, 13:06

Your query sounds like it is a program development issue, rather than xplorer2-related.
Yup it is.
Although you might get a constructive reply from nikos or our readers, you are likely to get more help sooner from the the users at The Code Project: http://www.codeproject.com/  
Has nikos implemented the context menus for the scrap container and has it be working fine?

Jim

User avatar
fgagnon
Site Admin
Site Admin
Posts: 3737
Joined: 2003 Sep 08, 19:56
Location: Springfield

Post by fgagnon » 2007 Aug 13, 13:23

Yes and Yes (at least I have no problems with them)

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 14, 18:34

Hey Nikos,

  Looks like Xplorer2 has the same problems I am having.  It does weird things in Win2k if you have too many different kinds of file types and will crash.  I am thinking the right thing to do is only put the file type of the currently focused node and then special types like "*", "AllSystemsFiles", etc.

 I will keep you posted.

Jim

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 28, 05:59

Wish I knew you were so close to me, we could have talked shell over a beer (ok a few hundred miles).  I almost have it working in all versions of Windows.  The only thing I would like to understand is the Copy/Cut menu items.  I had to override GetAttribuitesOf as well and test if each item was SHAGO_CANMOVE/CANCOPY as with fully qualified PIDLs the desktop IShellFolder fails.  Did you have to do this?

Also it looks like win2k and 9x need either HKCR/Directory OR HKCR/Folder and not both when using a folder as the "focused" item in a list.  I am only running the registry on the extension of the item the use clicked over and that fixes the duplicate menu items and crashes I had and also see in xplorer2 on Win2k and 9x.

The keys I am using on the focused item are:

For Files:

HKCR\*
HKCR\AllFIleSystemObjects
HKCR\{.ext}
HKCR\\{FileClass}  (pointed to by default string of above, also checked for CurVer string)
HKCR\FileSystemAssociations\{.ext}
reading HKCR\{.ext}\PerceivedType and opening
HKCR\FileSystemAssociations\{PerceivedType}

if the extension is not found then using
HKCR\Unknown

For Directories:

HKCR\Folder
HKCR\Directory

Again this does not work right for Win2k and 9x, it seems to double up the "Main" verbs (Open, Explorer, Print, etc)  I will let you know what do do for those OS's when I get some time to figure it out.

Jim

User avatar
nikos
Site Admin
Site Admin
Posts: 14484
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2007 Aug 30, 11:38

haven't tried on win2K recently, but for XP i just tried a context menu on 2500 files (various) and both the menu and the execution of commands was pronto

perhaps for w2000 there are the same problems as with multi file properties, and this patch may be useful:
http://support.microsoft.com/default.as ... s%3B330040

finally i don't use these keys at all:
HKCR\FileSystemAssociations\{.ext}
HKCR\FileSystemAssociations\{PerceivedType}

hth
nikos

ps
Wish I knew you were so close to me, we could have talked shell over a beer
you're in belgium right, the best beer in the world :)
why don't you come to this year's ESWC ?

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 31, 03:03

Here is what it looks like on Win2k

http://www.mustangpeak.net/2xplorer.bmp

haven't tried on win2K recently, but for XP i just tried a context menu on 2500 files (various) and both the menu and the execution of commands was pronto
Yes it work on Vista and XP (though I did get it to crash and vanish on XP).

perhaps for w2000 there are the same problems as with multi file properties, and this patch may be useful:
http://support.microsoft.com/default.as ... s%3B330040
It does not "feel" like that is the problem.
finally i don't use these keys at all:
HKCR\FileSystemAssociations\{.ext}
HKCR\FileSystemAssociations\{PerceivedType}
Then how do you get the "Print" menu item?  That was the only way I could get it.  I use RegMon to look at what the Explorer Search window was opening and it uses these keys.
you're in belgium right, the best beer in the world Smile
why don't you come to this year's ESWC ?
Nope that is Cyber (http://www.cubicreality.com).  I live in Arizona.

Jim

User avatar
nikos
Site Admin
Site Admin
Posts: 14484
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2007 Aug 31, 11:00

i managed to crash it on 2000 and more worryingly on vista for huge file collections :(

how many files did you have selected in that x2 snapshot you sent with the gazillion open/print menu commands?
I live in Arizona
then we lost the opportunity for beer last week when i was crossing arizona (driving from las vegas to jackson hole). Nice rugged country!

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 31, 13:38

i managed to crash it on 2000 and more worryingly on vista for huge file collections
My experience as well.
how many files did you have selected in that x2 snapshot you sent with the gazillion open/print menu commands?
You can see in the shot.  Less than a dozen.

Can you share how you are loading the PHKEY structure, with what keys?  I have it work 100% now on all version of windows (did not try NT or 95).  No crashes and no duplicate items.

Jim

User avatar
nikos
Site Admin
Site Admin
Posts: 14484
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2007 Aug 31, 14:06

i think i got most of the keys from one of your delphi samples that i dug up from google, so no surprises there! It is as I described in the blog with the addition of:

folder
directory
AllFilesystemObjects

so how did you stop crashes and duplicates?

JimKueneman
Member
Member
Posts: 13
Joined: 2007 Aug 13, 04:40

Post by JimKueneman » 2007 Aug 31, 14:43

so how did you stop crashes and duplicates?
I don't know.  I do know that somehow we are doing something different as I said I could not get the "Print" item until I used this:

HKCR\FileSystemAssociations\{.ext}
HKCR\FileSystemAssociations\{PerceivedType}

In a nut shell this is what I am doing:

Load and array with the AbsolutePIDLs for all selected items then prepare what keys to load:

Code: Select all

procedure TCommonShellMultiParentContextMenu.LoadRegistryKeyStrings(Focused: TNamespace);
begin
  KeyStrings.Clear;
  Extensions := [cmeShellDefault, cmeAsterik, cmeAllFilesystemObjects, cmeFileSystemAssociations];

  // Only add the menu handlers for the focused item class
  if Assigned(Focused) then
  begin
    if Focused.Folder then
      Extensions := [cmeShellDefault, cmeFolder]
    else
      AddMenuKey(WideExtractFileExt(Focused.NameForParsing));
  end
end;
KeyStrings here is a string list that is a hold over from when I was loading ALL extensions that were selected.  No ALL that is in it is the extension of the item that the user right clicked over (the "Focused" node in my terminology here)

Now when I show the menu I do this:

Code: Select all

if cmeDirectory in Extensions then
                AddMenuKey('Directory');
              if cmeDirBackground in Extensions then
                AddMenuKey('Directory\Background');
                if cmeFolder in Extensions then
                AddMenuKey('Folder');
              if cmeAsterik in Extensions then
                AddMenuKey('*');
              if cmeAllFilesystemObjects in Extensions then
                AddMenuKey('AllFilesystemObjects');
Now the KeyStrings string list contains

1) the extension of the "Focused" node
2) '*'
3) 'AllFilesystemObjects'

IF the Focused item was a file ELSE it contains

1) 'Folder'

What cmeShellDefault does is cause DFM_MERGECONTEXTMENU to return S_OK in the callback

Now with the reg key list all loaded I start drilling into the hive.

Code: Select all

UnknownAdded := False;
              Reg := TTntRegistry.Create;
              try
                Reg.Access := KEY_READ;
                Reg.RootKey := HKEY_CLASSES_ROOT;
                for i := 0 to KeyStrings.Count - 1 do
                begin
                  if (KeyStrings[i] <> '') then
                  begin
                    if Reg.OpenKey(KeyStrings[i], False) then
                    begin
                      // The extension key is open {.ext}
                      AddKey(DuplicateKey(Reg.CurrentKey), Keys);
                      WS := Reg.ReadString('');
                      Reg.CloseKey;
                      if WS <> '' then
                      begin
                        if Reg.OpenKey(WS, False) then
                        begin
                          // The FileClass is open, see if there is mulitiple version and a current version
                          if Reg.KeyExists('CurVer') then
                          begin
                            if Reg.OpenKey('CurVer', False) then
                            begin
                              CurVer := Reg.ReadString('');
                              if Reg.OpenKey('\' + CurVer, False) then
                                AddKey(DuplicateKey(Reg.CurrentKey), Keys);
                            end;
                            Reg.CloseKey;
                          end else
                          begin
                            AddKey(DuplicateKey(Reg.CurrentKey), Keys);
                            Reg.CloseKey;
                          end
                        end
                      end
                    end else
                    begin
                      if not UnknownAdded and Reg.OpenKey('Unknown', False) then
                      begin
                        AddKey(DuplicateKey(Reg.CurrentKey), Keys);
                        Reg.CloseKey;
                        UnknownAdded := True
                      end
                    end;

                    if cmeFileSystemAssociations in Extensions then
                    begin
                      if Reg.OpenKey('SystemFileAssociations\' + KeyStrings[i], False) then
                      begin
                        AddKey(DuplicateKey(Reg.CurrentKey), Keys);
                        Reg.CloseKey;
                      end
                    end;

                    if cmePerceivedType in Extensions then
                    begin
                      if Reg.OpenKey(KeyStrings[i], False) then
                      begin
                        WS := Reg.ReadString('PerceivedType');
                        if WS <> '' then
                        begin
                          if Reg.OpenKey('\SystemFileAssociations\' + WS, False) then
                            AddKey(DuplicateKey(Reg.CurrentKey), Keys);
                        end;
                        Reg.CloseKey;
                      end
                    end
                  end
                end
              finally
                Reg.CloseKey;
                Reg.Free
              end;

I think that is self explanatory if not let me know.  The main thing is searching for the right file class through the CurVal key and if the extension is not found using the "Unknown" key.  What I just noticed is I now have the "Print" item but I am not defining cmePerceivedType so that key is not being used..... I don't know now.  I have tried and experimented so much over the last few weeks I am getting myself confused  :oops:

Anyway the way I show seems to be working.

Jim

Post Reply