Qter 发表于 2020-9-9 17:59:50

sysinfo

本帖最后由 Qter 于 2020-9-9 18:45 编辑

var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");


Services.sysinfo.getProperty("name")XPCOMUtils.defineLazyGetter(this, "OSVersion", function UFS_OSVersion() {
    let OSVersion = "default";
    let sysInfo = Cc["@mozilla.org/system-info;1"].getService(
      Ci.nsIPropertyBag2
    );
    try {
      OSVersion =
      sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
      OSVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
    } catch (e) {}

    return encodeURIComponent(OSVersion);
});https://searchfox.org/comm-central/source/mozilla/xpcom/build/components.conf#191 {
      'js_name': 'sysinfo',
      'cid': '{d962398a-99e5-49b2-857a-c159049c7f6c}',
      'contract_ids': ['@mozilla.org/system-info;1'],
      'interfaces': ['nsIPropertyBag2', 'nsISystemInfo'],
      'type': 'nsSystemInfo',
      'headers': ['nsSystemInfo.h'],
      'init_method': 'Init',
      'overridable': True,
    },https://searchfox.org/comm-central/source/mozilla/xpcom/base/nsSystemInfo.h
https://searchfox.org/comm-central/source/mozilla/xpcom/base/nsSystemInfo.cpp

PR_SI_RELEASE_BUILD
https://searchfox.org/comm-central/source/mozilla/nsprpub/pr/src/misc/prsystem.c#155
https://searchfox.org/comm-central/source/mozilla/nsprpub/pr/include/prsystem.h#48


_PR_MD_GETSYSINFO -> _MD_GETSYSINFO -> _MD_WindowsGetSysInfo
https://searchfox.org/comm-central/source/mozilla/nsprpub/pr/src/md/windows/ntmisc.c#811
PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen)




Qter 发表于 2020-9-10 14:31:31

本帖最后由 Qter 于 2020-9-10 14:33 编辑

Resolving Redefinition Errors Betwen ws2def.h and winsock.h
https://www.zachburlingame.com/2011/05/resolving-redefinition-errors-betwen-ws2def-h-and-winsock-h/
The SolutionYou basically have three options to fix this:Option 1: WIN32_LEAN_AND_MEANDefining WIN32_LEAN_AND_MEAN will reduce the size of the Windows headers by excluding several APIs, including Windows Sockets.#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <WinSock2.h>

int main( int argc, char* argv[] )
{
return 0;
}Option 2: Explicitly include WinSock2.h before Windows.hBy explicitly including WinSock2.h before every place that you Windows.h, you prevent the collision. However, this can be quite cumbersome at times.
UPDATE 2011-11-12:This method can cause issues with struct packing and alignment if WIN32 isn’t defined before including WinSock2.h (see Oren’s comment below). To resolve this issue, either define WIN32 as a preprocessor flag in your project or explicitly define #WIN32 prior to the WinSock2.h include as I’ve done below.
#ifndef WIN32
#define WIN32
#endif
#include <WinSock2.h>
#include <Windows.h>

int main( int argc, char* argv[] )
{
return 0;
}
Option 3: Create a WinSock Wrapper HeaderThis option creates a header file that prevents the collision in the first place and then you include this at (or nearest as possible) to the top of every file that needs WinSock2.h.The following is based on code from this stackoverflowanswer.

#ifndef _WINSOCK_WRAPPER_H_
#define _WINSOCK_WRAPPER_H_

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _WINDOWS_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif

#include <winsock2.h>

#pragma comment(lib, "ws2_32.lib")

#endif
If the #pragma option above is unfamiliar to you, the compiler passes it along to the linker telling it to include the lib rather than having to set it in the project settings. Theres more on #pragma comment options over on MSDN.



Qter 发表于 2020-9-10 18:24:55

// Setup the command line arguments to sign the MAR.
https://searchfox.org/comm-central/source/mozilla/modules/libmar/tests/unit/test_sign_verify.js#22

Qter 发表于 2020-9-10 18:28:22

this._hddData = await Services.sysinfo.diskInfo;
let osData = await Services.sysinfo.osInfo;
https://searchfox.org/comm-central/source/mozilla/toolkit/components/telemetry/app/TelemetryEnvironment.jsm#1086

页: [1]
查看完整版本: sysinfo