rv = (*aResult)->GetParent( getter_AddRefs( startDir ) );
nsCOMPtr<nsIFileSpec> startDirPath; rv = (*aResult)->GetParent( getter_AddRefs(startDirPath));   nsFileSpec startDirSpec;  if (NS_SUCCEEDED(rv)) rv = startDirPath->GetFileSpec(&startDirSpec);  if (NS_SUCCEEDED(rv)) rv = NS_FileSpecToIFile(&startDirSpec, getter_AddRefs(startDir));
nsStreamTransfer::SelectFile( nsIDOMWindow *parent, nsIFileSpec **aResult, const nsCString &suggested ) {    nsresult rv = NS_OK;    if ( aResult ) {        *aResult = 0;        // Prompt user for file name.        nsCOMPtr<nsIFilePicker> picker = do_CreateInstance( "component://mozilla/filepicker" );              if ( picker ) {            // Prompt for file name.            nsCOMPtr<nsIFileSpec> startDir;            // Pull in the user's preferences and get the default download directory.            NS_WITH_SERVICE( nsIPref, prefs, NS_PREF_PROGID, &rv );            if ( NS_SUCCEEDED( rv ) && prefs ) {                prefs->GetFilePref( "browser.download.dir", getter_AddRefs( startDir ) );                if ( startDir ) {                    PRBool isValid = PR_FALSE;                    startDir->IsValid( &isValid );                    if ( isValid ) {                        // Set file picker so startDir is used.                        nsXPIDLCString nativeStartDir;                        startDir->GetNativePath( getter_Copies( nativeStartDir ) );                        nsCOMPtr<nsILocalFile> startLocalFile;                        if ( NS_SUCCEEDED( NS_NewLocalFile( nativeStartDir, PR_FALSE, getter_AddRefs( startLocalFile ) ) ) ) {                            #ifdef DEBUG_law                            printf( "\nSetting display directory to %s\n\n", (const char*)nativeStartDir );                            #endif                            picker->SetDisplayDirectory( startLocalFile );                        }                    }                }            }            nsAutoString title( NS_ConvertASCIItoUCS2( "Save File" ) );            nsCID cid = NS_STRINGBUNDLESERVICE_CID;            NS_WITH_SERVICE( nsIStringBundleService, bundleService, cid, &rv );            if ( NS_SUCCEEDED( rv ) ) {                nsILocale *locale = 0;                nsIStringBundle *bundle;                PRUnichar *pString;                rv = bundleService->CreateBundle( "chrome://global/locale/downloadProgress.properties",                                                  locale,                                                   getter_AddRefs( &bundle ) );                if ( NS_SUCCEEDED( rv ) ) {                    rv = bundle->GetStringFromName( NS_ConvertASCIItoUCS2( "FilePickerTitle" ).GetUnicode(),                                                    &pString );                    if ( NS_SUCCEEDED( rv ) && pString ) {                        title = pString;                        nsAllocator::Free( pString );                    }                }            }                    rv = picker->Init( parent, title.GetUnicode(), nsIFilePicker::modeSave );            PRInt16 rc = nsIFilePicker::returnCancel;            if ( NS_SUCCEEDED( rv ) ) {                // Set default file name.                rv = picker->SetDefaultString( NS_ConvertASCIItoUCS2( suggested.GetBuffer() ).GetUnicode() );                // Set file filter mask.                rv = picker->AppendFilters( nsIFilePicker::filterAll );                rv = picker->Show( &rc );            }            #ifdef DEBUG_law            printf( "\nFile picker result = 0x%04X\n\n", (int)rc );            #endif            if ( rc != nsIFilePicker::returnCancel ) {                // Give result to caller.                nsCOMPtr<nsILocalFile> selection;                if ( NS_SUCCEEDED( picker->GetFile( getter_AddRefs( selection ) ) ) ) {                    nsXPIDLCString selectionPath;                    if ( NS_SUCCEEDED( selection->GetPath( getter_Copies( selectionPath ) ) ) ) {                        rv = NS_NewFileSpec( aResult );                        if ( NS_SUCCEEDED( rv ) ) {                            rv = (*aResult)->SetNativePath( selectionPath );                            printf( "\nresult native path = %s\n\n", (const char *)selectionPath );                        }                    }                }                if ( NS_SUCCEEDED( rv ) && prefs ) {                    // Save selected directory for next time.                    rv = (*aResult)->GetParent( getter_AddRefs( startDir ) );                    if ( NS_SUCCEEDED( rv ) && startDir ) {                        prefs->SetFilePref( "browser.download.dir", startDir, PR_FALSE );                        #ifdef DEBUG_law                        printf( "\nbrowser.download.dir has been reset\n\n" );                        #endif                    }                }            } else if ( NS_SUCCEEDED( rv ) ) {                // User cancelled.                rv = NS_ERROR_ABORT;            }        }    } else {        rv = NS_ERROR_NULL_POINTER;    }    return rv;}