From 3894473c87783c8c50b6bf14a6a14b9a636d879a Mon Sep 17 00:00:00 2001
From: open-license-manager <rillf@maildrop.cc>
Date: 摹曛, 07 8月 2014 05:12:31 +0800
Subject: [PATCH] windows dev

---
 src/bootstrap/win/Main.cpp |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/bootstrap/win/Main.cpp b/src/bootstrap/win/Main.cpp
index 26006c5..5db6b52 100644
--- a/src/bootstrap/win/Main.cpp
+++ b/src/bootstrap/win/Main.cpp
@@ -1,6 +1,8 @@
 #include <stdio.h>
 #include "CryptoHelper.h"
 #include <string>
+#include <stdlib.h>
+#include <iostream> 
 
 using namespace std;
 
@@ -19,8 +21,27 @@
 		fprintf(fp, "%d", pbPublicKey[i]);
 	}
 	fprintf(fp, "\n};\n\n");
-	fprintf(fp, "#define SHARED_RANDOM %d;\n", 12345);
+	int random = rand() % 1000;
+	fprintf(fp, "#define SHARED_RANDOM %d;\n", random);
 	fprintf(fp, "#endif\n");
+	fclose(fp);
+}
+
+void write_privkey_file(string private_fname, BYTE *privateKey, DWORD dwPrivateKeySize){
+	FILE* fp = fopen(private_fname.c_str(), "w");
+	fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n");
+	fprintf(fp, "#ifndef PRIVATE_KEY_H_\n#define PRIVATE_KEY_H_\n");
+	fprintf(fp, "static BYTE PRIVATE_KEY[] = {");
+	for (int i = 0; i < dwPrivateKeySize; i++){
+		if (i != 0){
+			fprintf(fp, ",");
+		}
+		if (i % 15 == 0){
+			fprintf(fp, "\n        ");
+		}
+		fprintf(fp, "%d", privateKey[i]);
+	}
+	fprintf(fp, "\n};\n\n");
 	fclose(fp);
 }
 
@@ -43,6 +64,7 @@
 	if (FAILED(
 			hr = cryptoHlpr.ExportPublicKey(&pbPublicKey, dwPublicKeySize))) {
 // Call FormatMessage to display the error returned in hr.
+		cerr << "error exporting pubkey" << endl;
 		return;
 	}
 	else {
@@ -56,7 +78,13 @@
 	}
 	wprintf(L"\"\n");
 	// Export out the private key blob.
-	cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize);
+	if (FAILED(cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize))){
+		cerr << "Error exporting private key." << endl;
+		return;
+	}
+	else{
+		write_privkey_file(private_include, pbPrivateKey, dwPrivateKeySize);
+	}
 	// Print out the private key to console as a
 	// hexadecimal string.
 	wprintf(L"\n\nPrivateKey = \"");

--
Gitblit v1.9.1