зеркало из https://github.com/mozilla/pjs.git
252189, XPCOM section:
add nsILocalFileWin interface and implementation with method to retrieve VERSIONINFO metadata from Windows binaries. r=dougt, sr=darin
This commit is contained in:
Родитель
e39a4ddeba
Коммит
f7ee487a02
|
@ -170,7 +170,7 @@ EXTRA_DSO_LDOPTS += -lbe
|
|||
endif
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME,shell32 ole32 uuid)
|
||||
EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME,shell32 ole32 uuid version)
|
||||
ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC))
|
||||
EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME,imagehlp)
|
||||
endif
|
||||
|
|
|
@ -130,6 +130,7 @@ XPIDLSRCS = \
|
|||
nsIFastLoadFileControl.idl \
|
||||
nsIFastLoadService.idl \
|
||||
nsIInputStreamTee.idl \
|
||||
nsILocalFileWin.idl \
|
||||
nsILineInputStream.idl \
|
||||
nsIMultiplexInputStream.idl \
|
||||
nsIObjectInputStream.idl \
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Local File Interface (Windows Extensions)
|
||||
*
|
||||
* The Initial Developer of the Original Code is Google Inc.
|
||||
* Portions created by the Initial Developer are
|
||||
* Copyright (C) 2005 the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@mozilla.org> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "nsILocalFile.idl"
|
||||
|
||||
[scriptable, uuid(dc42f467-4094-437d-9e3e-8912a072aede)]
|
||||
interface nsILocalFileWin : nsILocalFile
|
||||
{
|
||||
/**
|
||||
* getVersionInfoValue
|
||||
*
|
||||
* Retrieve a metadata field from the file's VERSIONINFO block.
|
||||
* Throws NS_ERROR_FAILURE if no value is found, or the value is empty.
|
||||
*
|
||||
* @param aField The field to look up.
|
||||
*
|
||||
*/
|
||||
AString getVersionInfoField(in string aField);
|
||||
};
|
||||
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
@ -448,7 +449,7 @@ nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void*
|
|||
// nsLocalFile::nsISupports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsLocalFile, nsILocalFile, nsIFile, nsILocalFileWin)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -995,6 +996,77 @@ nsLocalFile::GetNativePath(nsACString &_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
WORD wLanguage;
|
||||
WORD wCodePage;
|
||||
} LANGANDCODEPAGE;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetVersionInfoField(const char* aField, nsAString& _retval)
|
||||
{
|
||||
nsresult rv = ResolveAndStat();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
// Cast away const-ness here because WinAPI functions don't understand it,
|
||||
// the path is used for [in] parameters only however so it's safe.
|
||||
char *path = NS_CONST_CAST(char*, mFollowSymlinks ? mResolvedPath.get()
|
||||
: mWorkingPath.get());
|
||||
|
||||
// Per http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/versioninformation/versioninformationreference/versioninformationfunctions/getfileversioninfosize.asp
|
||||
// if the "short" version of this file name is > 125 characters,
|
||||
// GetFileVersionInfoSize will not work (for Win9x compatibility)
|
||||
char shortPath[126];
|
||||
::GetShortPathName(path, shortPath, sizeof(shortPath));
|
||||
|
||||
DWORD dummy;
|
||||
DWORD size = ::GetFileVersionInfoSize(shortPath, &dummy);
|
||||
if (!size)
|
||||
return rv;
|
||||
|
||||
void* ver = calloc(size, 1);
|
||||
if (!ver)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (::GetFileVersionInfo(path, 0, size, ver))
|
||||
{
|
||||
LANGANDCODEPAGE* translate = nsnull;
|
||||
UINT pageCount;
|
||||
BOOL queryResult = ::VerQueryValue(ver, "\\VarFileInfo\\Translation",
|
||||
(void**)&translate, &pageCount);
|
||||
if (queryResult && translate)
|
||||
{
|
||||
for (PRInt32 i = 0; i < 2; ++i)
|
||||
{
|
||||
char subBlock[MAX_PATH];
|
||||
PR_snprintf(subBlock, sizeof(subBlock),
|
||||
"\\StringFileInfo\\%04x%04x\\%s",
|
||||
(i == 0 ? translate[0].wLanguage
|
||||
: ::GetUserDefaultLangID()),
|
||||
translate[0].wCodePage, aField);
|
||||
|
||||
LPVOID value = nsnull;
|
||||
UINT size;
|
||||
queryResult = ::VerQueryValue(ver, subBlock, &value, &size);
|
||||
if (queryResult && value)
|
||||
{
|
||||
NS_CopyNativeToUnicode(nsDependentCString((const char*)value), _retval);
|
||||
if (!_retval.IsEmpty())
|
||||
{
|
||||
rv = NS_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(ver);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const nsACString &newName,
|
||||
PRBool followSymlinks, PRBool move)
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsILocalFileWin.h"
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
|
@ -60,7 +61,7 @@ DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0);
|
|||
|
||||
#include <sys/stat.h>
|
||||
|
||||
class nsLocalFile : public nsILocalFile
|
||||
class nsLocalFile : public nsILocalFileWin
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
|
||||
|
@ -78,6 +79,9 @@ public:
|
|||
// nsILocalFile interface
|
||||
NS_DECL_NSILOCALFILE
|
||||
|
||||
// nsILocalFileWin interface
|
||||
NS_DECL_NSILOCALFILEWIN
|
||||
|
||||
public:
|
||||
static void GlobalInit();
|
||||
static void GlobalShutdown();
|
||||
|
|
Загрузка…
Ссылка в новой задаче