source: trunk/gsinstaller/gsProfile.cpp@ 2013

Last change on this file since 2013 was 1541, checked in by cs025, 24 years ago

Fixes for WindowsNT. Also made File class subclass of FilePath class.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1#include "gsProfile.h"
2
3#include <stdio.h>
4
5gsProfile::gsProfile(installManager &manager, string fileName)
6 : installAgent(manager)
7{ this->fileName = fileName;
8}
9
10void gsProfile::logAction(string action, string sectionName, string item,
11 string value)
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);
18}
19
20bool gsProfile::undoAction(string actionName, stringArray &params)
21{ if (actionName == "ProfileAddListMember")
22 { this->removeListMember(params[0], params[1], params[2]);
23 return true;
24 }
25 return false;
26}
27
28bool gsProfile::ensureListMember(string sectionName, string listName,
29 string listMember)
30{ char buffer[256] = "\0";
31 stringArray *members;
32 bool reply = true;
33
34 if (GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
35 buffer, 256, this->fileName.c_str()) <= 0)
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);
43
44 reply = this->writeString(sectionName, listName, buffer);
45 if (reply)
46 { this->logAction("ProfileAddListMember", sectionName, listName, listMember);
47 }
48 }
49 delete members;
50 return reply;
51}
52
53bool gsProfile::addListMember(string sectionName, string listName, string listMember)
54{ char buffer[256];
55 stringArray *members;
56
57 GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
58 buffer, 256, this->fileName.c_str());
59 // straightforward, unthinking, add
60 members = new stringArray(buffer, ";");
61 members->add(listMember);
62 members->writeToCString(buffer, ";", 256);
63 delete members;
64 return this->writeString(sectionName, listName, buffer);
65}
66
67bool gsProfile::removeListMember(string sectionName, string listName, string listMember)
68{ char buffer[256];
69 stringArray *members;
70
71 GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
72 buffer, 256, this->fileName.c_str());
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
80 return this->writeString(sectionName, listName, buffer);
81}
82
83bool 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()))
86 { DWORD error = GetLastError();
87/* char buffer[20];
88 sprintf(buffer, "%lx", error);
89 MessageBox(0, buffer, "", MB_OK);*/
90 return false;
91 }
92 return true;
93}
Note: See TracBrowser for help on using the repository browser.