Tuesday, September 15, 2009

Not every computer is online

I had to test some installers yesterday. Four of them. I needed to run them on a virgin machine, so I could test all the installation of prerequisites. So, I wiped my notebook, and put Vista on it, using the factory install DVD. I hoped to use the XP on the machine, but I'd never activated it, and despite having a license, activation failed. So, I went the quickest route open to me.

Vista is frustrating, as always. In fact, after running the uninstaller once, I found that the control panel stopped working. It would flash up and disappear. If I ran in safe mode, it works, but gives an obscure message about permissions when I try to uninstall something. For the record, I installed .NET 3.5, Acrobat, and my program, so one of those screwed it up. I was able to keep working by running Programs and Features ( because they HAD to rename it in Vista, or it may have been easy to find the first time I used it ), from My Computer.

So, my installer is running, and taking *forever*. I know the stupid .NET 3.5 install claims to be downloading, even tho I have the full version on the DVD. I suddenly realise, it's trying to connect to download, even though it doesn't need to, and timing out five times before noticing it has the data locally. Then it moves up a bit, and repeats the sequence. It's bad enough that our clients are shown a screen saying that .NET 3.5 is downloading, when it's not, but this is just the height of stupidity in my opinion. I was at a family dinner, testing, so I didn't have the option of connecting to the web, which slowed down my work considerably. Another example of Microsoft's inability to see past their own assumptions, and consider what the possible situation of real users may just well be.



Tuesday, September 1, 2009

Consistency

So, I am using the Windows Media Player control within my WPF project, because the built in control is too slow. My problem is, I want the control to not play the video right away, but to have it loaded, so there's no moment of black screen when you press play. The only way I can see to do this, is to turn off the volume, tell it to play, and when it starts, pause it and turn the volume back on. Which is, of course, messy.

What is also messy, is that when I search the MSDN, the media play control has a ton of different types of volume settings. One allows for the volume to go between 0.0 and 1.0, with 0.0 being off. At other times, the windows media player control apparently has settings between 0 and -10,000, where 0 is full volume. When I find the right documentation, for the right version of the object, it tells me that the settings property "... gets an IWMPSettings interface that provides a way to modify various Windows Media Player settings." What is a IWMPSettings interface ? What does it expose ? I did find a link which would tell me that, and, for the purposes of the COM control, under C#, the range is 0 to 100. I think. I mean, it's not really clear enough for me to be sure, given all the other options I have been given. I'll try that and see.

My point today is - why does Microsoft have to do the same thing 100 different ways ? Why can't they just decide on something and stick to it ?

Monday, August 17, 2009

How is this possible ?

OK, so I have a media player control in my WPF app. For reasons that I cannot fathom, WPF does not let me easily find out the native size of a video, so I have added a map of video paths to sizes. I have built this map, and when I load a video, I grab a screenshot of the first frame. After that, you can play and pause the video, when you pause, it goes to the static screenshot, so that it will appear in screen grabs, which we print and email.

if (MediaAccessManager.Instance.VideoSizeMap.ContainsKey(srcPath))

This is the line of code I use to check if I have a size for this video in my map ( users can import their own videos and then I need to just use DirectX via a third party dll to find the size. I don't do this for my own videos, because sometimes the size reported, is incorrect. Here is the issue. The first time this code runs, I get an exception, stating that the key in question already exists in the collection. Believe me, I have read this code over and over, there is NO code here to put anything into the collection, nor does this crash after the first time. The only possible reason I can think of, is that perhaps the collection does not blow up when I put in a duplicate key, it blows up the first time I try to access it after the fact. However, I call ContainsKey before adding each item, and I have written some code to further confirm that I have no duplicate keys. I also wrote code to deliberately add the same key twice, and it threw an exception at the point of adding the item, as you'd expect.

I really don't have time to debug this, so I've added the block of code above in it's own try/catch. The first time this runs, it throws an exception, but then it does it again right away, and the second time it works fine, causing my code to work perfectly. It's just not at all pretty.

Sunday, August 9, 2009

Why can't I drag and drop a csproj file ?

I was reminded again today that if I drag and drop a sln or csproj file onto the main window of VS2008, I get a message box saying that I am not allowed to do that.  It doesn 't even open File/Open for me, just tells me I need to do it.  Why ? I can't think of any reason for them to insert a message box instead of a jump to the code that opens a project ( with a prompt if they would feel better that way ).  Whose smart idea was that ? It's just a pain.

Wednesday, August 5, 2009

Path.Combine is essentially useless

One of the great things about .NET, coming from C++, is all the stuff that is built in.  Need to send an email ? Sure thing.  Want to use regular expressions ? Go for it.  It took me a while to learn that things I expected to write in C++, I could look for in the library and often find there already.

The System.IO namespace has a Path class, which is used to manipulate file paths.  Things like 'GetFileNameWithoutExtension' are very, very useful.  Some things are a little counter intuitive, such as Path.GetDirectory walking up the directory tree if the string you have is a directory already, but overall, it saves a lot of work.

One of the things I use the most, is Path.Combine, which takes two fragments and merges them to make a path.  In the past, I'd be checking if one string had a trailing slash, if the other had a leading slash, etc.  Path.Combine takes care of that for you.  Right ? Not quite.

There's a couple of quirks here.  To illustrate, the following table has three columns.  The first two are the arguments passed into Path.Combine, the third is the result.


c:\path\dir\file.txtc:\path\dir\file.txt
c:\path\\dir\file.txt\dir\file.txt
c:\pathdir\file.txtc:\path\dir\file.txt
c:\path\dir\file.txt\dir\file.txt
c:dir\file.txtc:dir\file.txt
c:\dir\file.txt\dir\file.txt

The first thing to notice, is that if the second string starts with a \, then you get the second string back verbatim.  This is the issue that hit me in the past.  I assumed that this method existed so no matter what slashes happened to be in the two strings, they would get joined into a single path.  As you can see, this is not so.  Now, I assume there's a specific case for which this behaviour is desirable, but it's not the most obvious one to me, and if there's a reason for it, surely the method could have an overload, or better yet, a method called something in line with the reasoning for not combining these two strings could exist ( a method called Combine, is one I call to combine strings, not to SOMETIMES Combine them ).

The second one is more interesting.  If my first string is a drive letter, with no slash in it, then no slash is added.  I just did a test, I have a file called c:\procs.txt.  File.Exists (@"c:procs.txt") returns false, File.Exists(@"c:\procs.txt") returns true.  So, it seems to me that the slash is needed, but Path.Combine does not add it.  

Overall, this method is basically broken as far as I am concerned, and I have rolled my own version to use instead.  It basically makes sure the first string has a \ at the end, the second doesn't have one at the start, then calls Path.Combine, just out of spite ( given that at this point I could just concatenate the two strings and be done with it )
 

Thursday, July 30, 2009

WPF designer cannot render most forms

I have written a few projects in WPF now. What I don't understand is, why is the designer so fragile ? It seems as soon as I create any sort of reusable control, and use it on a form, even though the control exists in the same code base as the form, the form will no longer be able to render properly, it will report errors, which are invariably 'can't create an instance of MyCoolControl'. Of course, at run time it works fine, and the code for the control is right there, so I don't really understand what the issue is. I have talked to other people who have THEIR controls inside seperate dlls, which is apparently the recommended way to resolve this 'issue'. They still have the same error, and the way they have solved it, is by putting those dlls in the GAC.

Wait a minute. If I want to create a control inside my WPF app ( which is surely the OO way to do things, create it once and reuse it ), then I should create it in a seperate dll, and THEN put that dll in the GAC, so that the designer will work properly ? Am I the only person who thinks that is insane ?

Of course, I've not seen VS 2010, there is some possibility that this has been fixed. But, for now, it's a constant annoyance.

Tuesday, July 28, 2009

Pop unders/child windows

I am updating our website. So, in VS I open each image in my website, then I copy it to do a new screenshot in our updated UI. Then I save it from photoshop. Here's where the problem starts. VS opens a window telling me the image has been updated. I need to close this before VS becomes responsive again. Only, it's not a child window of the IDE, so I have to ALT-TAB looking for it every time, so I can close it. I know I've had other issues with popunder windows like this making other MS programs seem to freeze up. Is it that hard to set the owner of a window before you show it ? I don't know. I know it's frustrating to have to do over and over, because some basic UI rules were ignored.