[1397] | 1 | #include "gsProfile.h"
|
---|
| 2 |
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 |
|
---|
[1475] | 5 | gsProfile::gsProfile(installManager &manager, string fileName)
|
---|
| 6 | : installAgent(manager)
|
---|
[1397] | 7 | { this->fileName = fileName;
|
---|
| 8 | }
|
---|
| 9 |
|
---|
[1475] | 10 | void gsProfile::logAction(string action, string sectionName, string item,
|
---|
| 11 | string value)
|
---|
[1498] | 12 | { unInstallCommand command(action);
|
---|
| 13 | command.addParameter(this->fileName);
|
---|
| 14 | command.addParameter(sectionName);
|
---|
| 15 | command.addParameter(item);
|
---|
| 16 | command.addParameter(value);
|
---|
| 17 | manager->storeCommand(command);
|
---|
[1475] | 18 | }
|
---|
| 19 |
|
---|
| 20 | bool gsProfile::undoAction(string actionName, stringArray ¶ms)
|
---|
| 21 | { if (actionName == "ProfileAddListMember")
|
---|
| 22 | { this->removeListMember(params[0], params[1], params[2]);
|
---|
| 23 | return true;
|
---|
| 24 | }
|
---|
| 25 | return false;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | bool gsProfile::ensureListMember(string sectionName, string listName,
|
---|
| 29 | string listMember)
|
---|
[1397] | 30 | { char buffer[256] = "\0";
|
---|
| 31 | stringArray *members;
|
---|
[1475] | 32 | bool reply = true;
|
---|
[1397] | 33 |
|
---|
[1475] | 34 | if (GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
|
---|
| 35 | buffer, 256, this->fileName.c_str()) <= 0)
|
---|
[1397] | 36 | { buffer[0] = '\0';
|
---|
| 37 | }
|
---|
| 38 | // add if needsbe
|
---|
| 39 | members = new stringArray(buffer, ";");
|
---|
| 40 | if (members->includes(listMember) == false)
|
---|
| 41 | { members->add(listMember);
|
---|
| 42 | members->writeToCString(buffer, ";", 256);
|
---|
[1475] | 43 |
|
---|
| 44 | reply = this->writeString(sectionName, listName, buffer);
|
---|
| 45 | if (reply)
|
---|
| 46 | { this->logAction("ProfileAddListMember", sectionName, listName, listMember);
|
---|
| 47 | }
|
---|
[1397] | 48 | }
|
---|
| 49 | delete members;
|
---|
[1475] | 50 | return reply;
|
---|
[1397] | 51 | }
|
---|
| 52 |
|
---|
[1475] | 53 | bool gsProfile::addListMember(string sectionName, string listName, string listMember)
|
---|
[1397] | 54 | { char buffer[256];
|
---|
| 55 | stringArray *members;
|
---|
| 56 |
|
---|
[1475] | 57 | GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
|
---|
| 58 | buffer, 256, this->fileName.c_str());
|
---|
[1397] | 59 | // straightforward, unthinking, add
|
---|
| 60 | members = new stringArray(buffer, ";");
|
---|
| 61 | members->add(listMember);
|
---|
| 62 | members->writeToCString(buffer, ";", 256);
|
---|
| 63 | delete members;
|
---|
[1475] | 64 | return this->writeString(sectionName, listName, buffer);
|
---|
[1397] | 65 | }
|
---|
| 66 |
|
---|
[1475] | 67 | bool gsProfile::removeListMember(string sectionName, string listName, string listMember)
|
---|
[1397] | 68 | { char buffer[256];
|
---|
| 69 | stringArray *members;
|
---|
| 70 |
|
---|
[1475] | 71 | GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
|
---|
| 72 | buffer, 256, this->fileName.c_str());
|
---|
[1397] | 73 | // straightforward, unthinking, removal - if it isn't there, we won't need to
|
---|
| 74 | // worry!
|
---|
| 75 | members = new stringArray(buffer, ";");
|
---|
| 76 | members->remove(listMember);
|
---|
| 77 | members->writeToCString(buffer, ";", 256);
|
---|
| 78 | delete members;
|
---|
| 79 |
|
---|
[1475] | 80 | return this->writeString(sectionName, listName, buffer);
|
---|
[1397] | 81 | }
|
---|
| 82 |
|
---|
[1475] | 83 | bool gsProfile::writeString(string sectionName, string itemName, string itemValue)
|
---|
| 84 | { if (!WritePrivateProfileString( sectionName.c_str(), itemName.c_str(),
|
---|
| 85 | itemValue.c_str(), this->fileName.c_str()))
|
---|
[1397] | 86 | { DWORD error = GetLastError();
|
---|
[1541] | 87 | /* char buffer[20];
|
---|
[1397] | 88 | sprintf(buffer, "%lx", error);
|
---|
[1541] | 89 | MessageBox(0, buffer, "", MB_OK);*/
|
---|
| 90 | return false;
|
---|
[1397] | 91 | }
|
---|
| 92 | return true;
|
---|
| 93 | } |
---|