Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

configdialog.cpp 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include "configdialog.h"
  2. //(*InternalHeaders(configdialog)
  3. #include <wx/bitmap.h>
  4. #include <wx/button.h>
  5. #include <wx/font.h>
  6. #include <wx/image.h>
  7. #include <wx/intl.h>
  8. #include <wx/string.h>
  9. //*)
  10. //(*IdInit(configdialog)
  11. const long configdialog::ID_STATICBITMAP1 = wxNewId();
  12. const long configdialog::ID_STATICTEXT2 = wxNewId();
  13. const long configdialog::ID_STATICTEXT3 = wxNewId();
  14. const long configdialog::ID_STATICTEXT1 = wxNewId();
  15. const long configdialog::ID_HYPERLINKCTRL2 = wxNewId();
  16. const long configdialog::ID_HYPERLINKCTRL1 = wxNewId();
  17. //*)
  18. BEGIN_EVENT_TABLE(configdialog,wxDialog)
  19. //(*EventTable(configdialog)
  20. //*)
  21. END_EVENT_TABLE()
  22. bool fileExists(const std::string &fileName) {
  23. return std::ifstream(fileName.c_str()).good();
  24. }
  25. void configdialog::OnQuit(wxCommandEvent& event)
  26. {
  27. Close(TRUE);
  28. }
  29. std::string configdialog::utf8_encode(const std::wstring &wstr)
  30. {
  31. if( wstr.empty() ) return std::string();
  32. int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
  33. std::string strTo( size_needed, 0 );
  34. WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
  35. return strTo;
  36. }
  37. std::wstring getSNFFilePath() { // Get the config file path.
  38. std::wstring install_pathW;
  39. HKEY hKey;
  40. WCHAR szBuffer[512];
  41. DWORD dwBufferSize = sizeof(szBuffer);
  42. std::wstring regValue = L"";
  43. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Alt-N Technologies\\MDaemon", 0, KEY_READ, &hKey)){
  44. if(ERROR_SUCCESS == RegQueryValueEx(hKey, (LPCWSTR) L"AppPath", NULL, NULL, (LPBYTE) &szBuffer, &dwBufferSize)){
  45. RegCloseKey(hKey);
  46. regValue = std::wstring(szBuffer);
  47. std::wstring termCheck;
  48. for(auto val: regValue){
  49. if(val != L'\0'){
  50. termCheck += val;
  51. }
  52. }
  53. if(termCheck.size() == 512){
  54. regValue = L""; // RegValue wasn't null terminated
  55. }
  56. else{
  57. int PathEnd = regValue.length(); // Grab the length.
  58. if(PathEnd > 0) { regValue.erase(PathEnd-1,1); } // Eat the stroke at the end.
  59. PathEnd = regValue.find_last_of(L"\\"); // Find the next stroke in.
  60. int PathLength = regValue.length(); // Grab the path length.
  61. int EraseSpan = PathLength - (PathEnd+1); // Calculate the amount to erase.
  62. regValue.erase(PathEnd+1,EraseSpan); // Erase it to get the root path.
  63. regValue.append(L"SNF\\");
  64. }
  65. }
  66. }
  67. // Return either the empty string or the configuration file path.
  68. return regValue; // Return what we have.
  69. }
  70. configdialog::configdialog(wxWindow* parent,wxWindowID id)
  71. {
  72. install_path = utf8_encode(getSNFFilePath());
  73. wxBitmap logo = wxNullBitmap;
  74. std::string image_loc = install_path + "\\logo.png";
  75. if(fileExists(image_loc)){
  76. logo = wxBitmap(wxImage(image_loc));
  77. }
  78. //(*Initialize(configdialog)
  79. wxFlexGridSizer* FlexGridSizer10;
  80. wxFlexGridSizer* FlexGridSizer1;
  81. wxFlexGridSizer* FlexGridSizer2;
  82. wxFlexGridSizer* FlexGridSizer3;
  83. wxFlexGridSizer* FlexGridSizer4;
  84. wxFlexGridSizer* FlexGridSizer5;
  85. wxFlexGridSizer* FlexGridSizer6;
  86. wxFlexGridSizer* FlexGridSizer7;
  87. wxFlexGridSizer* FlexGridSizer8;
  88. wxFlexGridSizer* FlexGridSizer9;
  89. wxStdDialogButtonSizer* StdDialogButtonSizer1;
  90. Create(parent, wxID_ANY, _("SNF Configuration"), wxDefaultPosition, wxDefaultSize, wxSTAY_ON_TOP|wxCAPTION|wxDEFAULT_DIALOG_STYLE|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL, _T("wxID_ANY"));
  91. SetFocus();
  92. FlexGridSizer1 = new wxFlexGridSizer(6, 1, 1, 1);
  93. FlexGridSizer6 = new wxFlexGridSizer(0, 2, 0, 0);
  94. FlexGridSizer7 = new wxFlexGridSizer(0, 3, 0, 0);
  95. StaticBitmap1 = new wxStaticBitmap(this, ID_STATICBITMAP1, logo, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, _T("ID_STATICBITMAP1"));
  96. FlexGridSizer7->Add(StaticBitmap1, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  97. FlexGridSizer6->Add(FlexGridSizer7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  98. FlexGridSizer1->Add(FlexGridSizer6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  99. FlexGridSizer8 = new wxFlexGridSizer(3, 1, 0, 0);
  100. StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("SNF MDaemon Plugin Version 4.0"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
  101. wxFont StaticText2Font(12,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
  102. StaticText2->SetFont(StaticText2Font);
  103. FlexGridSizer8->Add(StaticText2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  104. FlexGridSizer9 = new wxFlexGridSizer(0, 3, 0, 0);
  105. StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("License ID: "), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
  106. wxFont StaticText3Font(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,true,_T("Arial"),wxFONTENCODING_DEFAULT);
  107. StaticText3->SetFont(StaticText3Font);
  108. FlexGridSizer9->Add(StaticText3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  109. FlexGridSizer8->Add(FlexGridSizer9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  110. FlexGridSizer3 = new wxFlexGridSizer(0, 1, 0, 0);
  111. StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("\n The full range of SNFServer features are provided by the plugin.\n All of these can be configured in the MDaemon/SNF/snfmdplugin.xml file.\n\n HOWEVER, some of the default settings are required in order\n for the plugin to work properly with MDaemon.\n\n In particular be careful about modifying <paths/> or <xheaders/>.\n"), wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER, _T("ID_STATICTEXT1"));
  112. FlexGridSizer3->Add(StaticText1, 1, wxALL, 10);
  113. FlexGridSizer8->Add(FlexGridSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
  114. FlexGridSizer1->Add(FlexGridSizer8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  115. FlexGridSizer2 = new wxFlexGridSizer(3, 1, 0, 0);
  116. FlexGridSizer4 = new wxFlexGridSizer(0, 3, 0, 0);
  117. HyperlinkCtrl2 = new wxHyperlinkCtrl(this, ID_HYPERLINKCTRL2, _("Click here to view your configuration file."), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_CONTEXTMENU|wxHL_ALIGN_CENTRE|wxNO_BORDER, _T("ID_HYPERLINKCTRL2"));
  118. FlexGridSizer4->Add(HyperlinkCtrl2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  119. FlexGridSizer2->Add(FlexGridSizer4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
  120. FlexGridSizer5 = new wxFlexGridSizer(0, 3, 0, 0);
  121. HyperlinkCtrl1 = new wxHyperlinkCtrl(this, ID_HYPERLINKCTRL1, _("Click here for more information."), _("https://www.armresearch.com/Documentation/QA/mdaemon_plugin-238282018.jsp"), wxDefaultPosition, wxDefaultSize, wxHL_CONTEXTMENU|wxHL_ALIGN_CENTRE|wxNO_BORDER, _T("ID_HYPERLINKCTRL1"));
  122. FlexGridSizer5->Add(HyperlinkCtrl1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  123. FlexGridSizer2->Add(FlexGridSizer5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  124. FlexGridSizer1->Add(FlexGridSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  125. StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
  126. StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK, wxEmptyString));
  127. StdDialogButtonSizer1->Realize();
  128. FlexGridSizer1->Add(StdDialogButtonSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  129. FlexGridSizer10 = new wxFlexGridSizer(0, 3, 0, 0);
  130. FlexGridSizer1->Add(FlexGridSizer10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  131. SetSizer(FlexGridSizer1);
  132. FlexGridSizer1->Fit(this);
  133. FlexGridSizer1->SetSizeHints(this);
  134. Connect(ID_HYPERLINKCTRL2,wxEVT_COMMAND_HYPERLINK,(wxObjectEventFunction)&configdialog::OnHyperlinkCtrl2Click);
  135. Connect(ID_HYPERLINKCTRL1,wxEVT_COMMAND_HYPERLINK,(wxObjectEventFunction)&configdialog::OnHyperlinkCtrl1Click);
  136. //*)
  137. //install_path = utf8_encode(install_pathW);
  138. std::string license_path = install_path + "\\identity.xml";
  139. if (fileExists(license_path)) {
  140. std::ifstream identity; // Grab the input file.
  141. identity.open(license_path.c_str(), // Open it in binary mode
  142. std::ios::in | std::ios::binary); // to avoid corruption issues.
  143. std::string line;
  144. std::string license_tag = "licenseid=\'";
  145. while (getline(identity, line)) // read in line
  146. {
  147. std::size_t found = line.find(license_tag);
  148. if (found!=std::string::npos){
  149. std::cout << "first 'needle' found at: " << found << '\n';
  150. StaticText3->SetLabel("License ID: " + line.substr(found+11, 8));
  151. }
  152. }
  153. }
  154. }
  155. configdialog::~configdialog()
  156. {
  157. //(*Destroy(configdialog)
  158. //*)
  159. }
  160. void configdialog::OnHyperlinkCtrl1Click(wxCommandEvent& event)
  161. {
  162. wxLaunchDefaultBrowser("https://www.armresearch.com/Documentation/QA/mdaemon_plugin-238282018.jsp");
  163. }
  164. void configdialog::OnHyperlinkCtrl2Click(wxCommandEvent& event)
  165. {
  166. wxLaunchDefaultApplication(install_path + "\\snfmdplugin.xml");
  167. }