source: trunk/gsinstaller/gsProfile.cpp@ 3177

Last change on this file since 3177 was 2534, checked in by cs025, 23 years ago

Added better monitoring of installation

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1#include "gsProfile.h"
2#include "FilePath.h"
3
4#include <stdio.h>
5
6gsProfile::gsProfile(installManager &manager, string fileName)
7 : installAgent(manager)
8{ FilePath path(fileName);
9
10 this->fileName = fileName;
11 if (path.exists() == false)
12 { this->logAction("ProfileCreate", "", "", "");
13 }
14}
15
16void gsProfile::logAction(string action, string sectionName, string item,
17 string value)
18{ unInstallCommand command(action);
19 command.addParameter(this->fileName);
20 command.addParameter(sectionName);
21 command.addParameter(item);
22 command.addParameter(value);
23 manager->storeCommand(command);
24}
25
26bool gsProfile::undoAction(string actionName, stringArray &params)
27{ if (actionName == "ProfileCreate")
28 { if (this->fileName == params[0])
29 { DeleteFile(params[0].c_str());
30 return true;
31 }
32 }
33 else if (actionName == "ProfileAddListMember")
34 { this->removeListMember(params[0], params[1], params[2]);
35 return true;
36 }
37 else if (actionName == "ProfileSetItem")
38 { this->removeString(params[1], params[2]);
39 return true;
40 }
41 return false;
42}
43
44bool gsProfile::ensureListMember(string sectionName, string listName,
45 string listMember)
46{ char buffer[256] = "\0";
47 stringArray *members;
48 bool reply = true;
49
50 if (GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
51 buffer, 256, this->fileName.c_str()) <= 0)
52 { buffer[0] = '\0';
53 }
54 // add if needsbe
55 members = new stringArray(buffer, ";");
56 if (members->includes(listMember) == false)
57 { members->add(listMember);
58 members->writeToCString(buffer, ";", 256);
59
60 reply = this->writeString(sectionName, listName, buffer);
61 if (reply)
62 { this->logAction("ProfileAddListMember", sectionName, listName, listMember);
63 }
64 }
65 delete members;
66 return reply;
67}
68
69bool gsProfile::addListMember(string sectionName, string listName, string listMember)
70{ char buffer[256];
71 stringArray *members;
72
73 GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
74 buffer, 256, this->fileName.c_str());
75 // straightforward, unthinking, add
76 members = new stringArray(buffer, ";");
77 members->add(listMember);
78 members->writeToCString(buffer, ";", 256);
79 delete members;
80 return this->writeString(sectionName, listName, buffer);
81}
82
83bool gsProfile::removeListMember(string sectionName, string listName, string listMember)
84{ char buffer[256];
85 stringArray *members;
86
87 GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
88 buffer, 256, this->fileName.c_str());
89 // straightforward, unthinking, removal - if it isn't there, we won't need to
90 // worry!
91 members = new stringArray(buffer, ";");
92 members->remove(listMember);
93 members->writeToCString(buffer, ";", 256);
94 delete members;
95
96 return this->writeString(sectionName, listName, buffer);
97}
98
99bool gsProfile::writeString(string sectionName, string itemName, string itemValue)
100{ if (!WritePrivateProfileString( sectionName.c_str(), itemName.c_str(),
101 itemValue.c_str(), this->fileName.c_str()))
102 { DWORD error = GetLastError();
103/* char buffer[201];
104 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, buffer, 200, NULL);
105 MessageBox(0, buffer, "Write error", MB_OK);
106*/
107
108 return false;
109 }
110 this->logAction("ProfileSetItem", sectionName, itemName, itemValue);
111 return true;
112}
113
114bool gsProfile::removeString(string sectionName, string itemName)
115{ if (!WritePrivateProfileString( sectionName.c_str(), itemName.c_str(),
116 NULL, this->fileName.c_str()))
117 { DWORD error = GetLastError();
118 if (error != 3)
119 { char buffer[201];
120
121 MessageBox(0, "Failed", itemName.c_str(), MB_OK);
122 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, buffer, 200, NULL);
123 MessageBox(0, buffer, "Write error", MB_OK);
124 return false;
125 }
126 WritePrivateProfileString(NULL, NULL, NULL, this->fileName.c_str());
127 MessageBox(0, this->fileName.c_str(), sectionName.c_str(), MB_OK);
128 }
129 return true;
130}
Note: See TracBrowser for help on using the repository browser.