コード例 #1
0
        private static bool TryGenerateProductID(string productKey, out Sku sku, out string pid, out Exception exception)
        {
            Sku[] array = new Sku[]
            {
                Sku.Ent64,
                Sku.Std64,
                Sku.Hybrid
            };
            sku       = null;
            pid       = null;
            exception = null;
            TaskLogger.Trace("-->GenerateProductId: {0}", new object[]
            {
                productKey
            });
            if (!File.Exists(Sku.PKConfigurationFile))
            {
                exception = new FileNotFoundException(Strings.CannotFindPKConfigFile(Sku.PKConfigurationFile));
                return(false);
            }
            Sku.DIGITALPID2 pPID       = new Sku.DIGITALPID2();
            Sku.DIGITALPID3 digitalpid = new Sku.DIGITALPID3();
            digitalpid.dwLength = (uint)Marshal.SizeOf(digitalpid);
            Sku.DIGITALPID4 digitalpid2 = new Sku.DIGITALPID4();
            digitalpid2.dwLength = (uint)Marshal.SizeOf(digitalpid2);
            uint num = Sku.PidGenX(productKey, Sku.PKConfigurationFile, "02064", null, pPID, digitalpid, digitalpid2);

            if (num == 0U)
            {
                string text      = new string(digitalpid.szSku);
                char[] trimChars = new char[1];
                string strA      = text.Trim(trimChars);
                foreach (Sku sku2 in array)
                {
                    if (string.Compare(strA, sku2.skuCode, StringComparison.Ordinal) == 0)
                    {
                        sku = sku2;
                        break;
                    }
                }
                if (sku != null)
                {
                    string text2      = new string(digitalpid.szPid2);
                    char[] trimChars2 = new char[1];
                    pid = text2.Trim(trimChars2);
                    TaskLogger.Trace("<--GenerateProductId: {0}: {1} => valid PID: {2}", new object[]
                    {
                        sku.name,
                        productKey,
                        pid
                    });
                    return(true);
                }
                TaskLogger.Trace("<--GenerateProductId: {0} => valid key, but for another SKU.", new object[]
                {
                    productKey
                });
                exception = new InvalidProductKeyException();
                return(false);
            }
            else
            {
                if (num == 2315321345U)
                {
                    TaskLogger.Trace("<--GenerateProductId: {0} => invalid product key config file format. {1}", new object[]
                    {
                        productKey,
                        num
                    });
                    exception = new InvalidPKConfigFormatException(Sku.PKConfigurationFile);
                    return(false);
                }
                TaskLogger.Trace("<--GenerateProductId: {0} => invalid product key. {1}", new object[]
                {
                    productKey,
                    num
                });
                exception = new InvalidProductKeyException();
                return(false);
            }
        }
コード例 #2
0
 private static extern uint PidGenX([MarshalAs(UnmanagedType.LPWStr)] string pwszProductKey, [MarshalAs(UnmanagedType.LPWStr)] string pwszConfig, [MarshalAs(UnmanagedType.LPWStr)] string pwszMpc, [MarshalAs(UnmanagedType.LPWStr)] string pwszOemId, [Out] Sku.DIGITALPID2 pPID2, [In][Out] Sku.DIGITALPID3 pPID3, [In][Out] Sku.DIGITALPID4 pPID4);