Merge pull request #24 from roytam1/nt351fix

NT 3.51 fixes
This commit is contained in:
rn10950 2018-07-24 00:50:20 -04:00 committed by GitHub
commit d97cd8e7c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 9 deletions

View File

@ -307,10 +307,12 @@ var gMainPane = {
*/
_folderToIndex: function (aFolder)
{
try {
if (!aFolder || aFolder.equals(this._getDownloadsFolder("Desktop")))
return 0;
else if (aFolder.equals(this._getDownloadsFolder("Downloads")))
return 1;
} catch(e) {}
return 2;
},
@ -326,8 +328,13 @@ var gMainPane = {
{
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var dir = fileLocator.get(this._getSpecialFolderKey(aFolder),
var dir;
try {
dir = fileLocator.get(this._getSpecialFolderKey(aFolder),
Components.interfaces.nsILocalFile);
} catch(e) {
dir = aFolder;
}
if (aFolder != "Desktop")
dir.append("My Downloads"); // XXX l12y!

View File

@ -515,9 +515,11 @@ function getTargetFile(aFpP, aSkipPrompt)
{
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var dir = fileLocator.get(getSpecialFolderKey(aFolder), Components.interfaces.nsILocalFile);
var dir;
try {
dir = fileLocator.get(getSpecialFolderKey(aFolder), Components.interfaces.nsILocalFile);
}
catch (e) {}
var bundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
bundle = bundle.createBundle("chrome://mozapps/locale/downloads/unknownContentType.properties");
@ -544,6 +546,7 @@ function getTargetFile(aFpP, aSkipPrompt)
if (!aSkipPrompt || !useDownloadDir || !dir) {
// If we're asking the user where to save the file, root the Save As...
// dialog on they place they last picked.
if(!dir) {
try {
dir = prefs.getComplexValue("lastDir", nsILocalFile);
}
@ -552,8 +555,15 @@ function getTargetFile(aFpP, aSkipPrompt)
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
dir = fileLocator.get(getSpecialFolderKey("Desktop"), nsILocalFile);
try {
dir = fileLocator.get(getSpecialFolderKey("Desktop"), nsILocalFile);
}
catch (r) {
// no clue, try current dir
dir = '.';
}
}
}
var fp = makeFilePicker();
var titleKey = aFpP.fpTitleKey || "SaveLinkTitle";

View File

@ -89,6 +89,7 @@ char nsFilePicker::mLastUsedDirectory[MAX_PATH+1] = { 0 };
nsFilePicker::nsFilePicker()
{
mSelectedType = 1;
mWinVer = GetVersion() & 0xFF;
}
//-------------------------------------------------------------------------
@ -153,7 +154,7 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
#ifndef WINCE
if (mMode == modeGetFolder) {
if (mMode == modeGetFolder && mWinVer > 3) {
PRUnichar dirBuffer[MAX_PATH+1];
wcsncpy(dirBuffer, initialDir.get(), MAX_PATH);
@ -244,13 +245,17 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
#ifndef WINCE
try {
#endif
if (mMode == modeOpen) {
if (mMode == modeOpen || mMode == modeGetFolder) {
// FILE MUST EXIST!
ofn.Flags |= OFN_FILEMUSTEXIST;
if(mMode == modeOpen) ofn.Flags |= OFN_FILEMUSTEXIST;
else {
fileBuffer[0]='t'; fileBuffer[1]='h'; fileBuffer[2]='i'; fileBuffer[3]='s';
fileBuffer[4]='D'; fileBuffer[5]='i'; fileBuffer[6]='r';
}
result = nsToolkit::mGetOpenFileName(&ofn);
}
else if (mMode == modeOpenMultiple) {
ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | (mWinVer > 3 ? OFN_EXPLORER : 0);
result = nsToolkit::mGetOpenFileName(&ofn);
}
else if (mMode == modeSave) {
@ -345,6 +350,17 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
}
}
else {
// Get DirPath from Full Pathname
if(mMode == modeGetFolder) {
int cnt;
nsAutoString dirName(fileBuffer);
for(cnt=dirName.Length()-1;cnt > 1; cnt--) {
if (fileBuffer[cnt] == '\\') {
fileBuffer[cnt] = 0;
break;
}
}
}
// I think it also needs a conversion here (to unicode since appending to nsString)
// but doing that generates garbage file name, weird.
mUnicodeFile.Assign(fileBuffer);

View File

@ -97,6 +97,7 @@ protected:
static char mLastUsedDirectory[];
nsString mUnicodeFile;
static nsString mLastUsedUnicodeDirectory;
PRInt32 mWinVer;
};
#endif // nsFilePicker_h__