Remove support for, and need for, changing directory in-process.
Chris Pressey
3 years ago
0 | 0 | #pragma once |
1 | 1 | |
2 | // configuration file | |
3 | #define REGISTRY "linapple.conf" | |
4 | 2 | extern FILE * registry; // our opened file |
5 | 3 | |
6 | 4 | BOOL RegLoadString (LPCTSTR,LPCTSTR,BOOL,char**,DWORD); |
6 | 6 | #include <string> |
7 | 7 | |
8 | 8 | #define USER_DIRECTORY_NAME "/linapple/" |
9 | #define REGISTRY_NAME "linapple.conf" | |
9 | 10 | #define CONF_DIRECTORY_NAME "/conf/" |
10 | 11 | #define SAVED_DIRECTORY_NAME "/saved/" |
11 | 12 | #define FTP_DIRECTORY_NAME "/ftp/" |
19 | 20 | Config(); |
20 | 21 | ~Config() {}; |
21 | 22 | |
22 | void ChangeToUserDirectory(); | |
23 | 23 | bool ValidateUserDirectory(); |
24 | 24 | bool CopyFile(std::string source, std::string dest); |
25 | 25 | std::string GetUserFilePath(); |
26 | std::string GetRegistryPath(); | |
26 | 27 | protected: |
27 | 28 | std::string GetHomePath(); |
28 | 29 | std::string GetInstallPath(); |
29 | 30 | private: |
30 | 31 | std::string m_optsFilePath; |
32 | std::string m_regFilePath; | |
31 | 33 | }; |
32 | 34 |
454 | 454 | |
455 | 455 | if(registry==NULL) |
456 | 456 | { |
457 | printf("File " REGISTRY " could not be opened. Using default configuration.\n"); | |
457 | printf("Registry file (linapple.conf) could not be opened. Using default configuration.\n"); | |
458 | 458 | return; |
459 | 459 | } |
460 | 460 | LOAD(TEXT("Computer Emulation"),&dwComputerType); |
795 | 795 | // GPH: The very first thing we do is attempt to grab the needed configuration files and put them in the user's folder. |
796 | 796 | Config config; |
797 | 797 | config.ValidateUserDirectory(); |
798 | config.ChangeToUserDirectory(); | |
799 | ||
800 | 798 | |
801 | 799 | // reading FullScreen and Boot from conf file? |
802 | 800 | bool bSetFullScreen = false; |
803 | 801 | bool bBoot = false; |
804 | 802 | |
805 | registry = fopen(REGISTRY, "rt"); // open conf file (linapple.conf by default) | |
803 | registry = fopen(config.GetRegistryPath().c_str(), "rt"); // open conf file (linapple.conf by default) | |
806 | 804 | spMono = fopen("speakersmono.pcm","wb"); |
807 | 805 | spStereo = fopen("speakersstereo.pcm","wb"); |
808 | 806 |
178 | 178 | |
179 | 179 | void RegSaveKeyValue(char * NKey, char * NValue) |
180 | 180 | { |
181 | #ifdef REGISTRY_WRITEABLE | |
182 | char MyStr[BUFSIZE]; | |
183 | char line[BUFSIZE]; | |
184 | char templine[BUFSIZE]; | |
185 | char *sztmp; | |
186 | FILE * tempf = tmpfile(); // open temp file | |
187 | // FILE * tempf = fopen("linapple-temp.conf", "w+"); | |
188 | if(!tempf) return; | |
189 | snprintf(MyStr, BUFSIZE, "\t%s =\t%s\n", NKey, NValue); // prepare string | |
190 | fseek(registry, 0, SEEK_SET); // | |
191 | bool found = false; | |
192 | ||
193 | while(fgets(line, BUFSIZE, registry)) | |
194 | { | |
195 | // printf("---1:%s", line); | |
196 | strcpy(templine, line); | |
197 | if(ReturnKeyValue(templine, &sztmp, &NValue) && !(strcmp(sztmp, NKey))) | |
198 | { | |
199 | fputs(MyStr, tempf); | |
200 | found = true; | |
201 | // printf("------ !!!!!!!!!!!!!!!! I FOUND IT!!!!!\n\n"); | |
202 | } | |
203 | else fputs(line, tempf); | |
204 | // printf("---2:%s", line); | |
205 | } | |
206 | ||
207 | if(!found) fputs(MyStr, tempf); | |
208 | // now swap tempf and registry | |
209 | fclose(registry); | |
210 | ||
211 | fflush(tempf); | |
212 | fseek(tempf, 0, SEEK_SET); | |
213 | // fclose(tempf); | |
214 | // return; | |
215 | registry = fopen(REGISTRY, "w+t"); // erase if been | |
216 | while(fgets(line, BUFSIZE, tempf)) { | |
217 | fputs(line, registry); | |
218 | // printf("---Saving Line:%s", line); | |
219 | } | |
220 | fflush(registry); | |
221 | fclose(tempf); | |
222 | // fflush(registry); // for chance... --bb | |
223 | // do not close registry, it should be open while emu working... | |
224 | #else | |
225 | printf("Attempt to set '%s' to '%s' ignored (registry is read-only)\n", NKey, NValue); | |
226 | #endif /* REGISTRY_WRITEABLE */ | |
181 | printf("Attempt to set '%s' to '%s' ignored (registry is read-only)\n", NKey, NValue); | |
227 | 182 | } |
228 | 183 | |
229 | 184 | //=========================================================================== |
24 | 24 | return m_optsFilePath.c_str(); |
25 | 25 | } |
26 | 26 | |
27 | void Config::ChangeToUserDirectory() | |
27 | std::string Config::GetRegistryPath() | |
28 | 28 | { |
29 | if(chdir((GetHomePath() + USER_DIRECTORY_NAME).c_str())) | |
30 | { | |
31 | ||
32 | cout << "Cannot switch to home directory ('" << GetHomePath().c_str() << "')" << std::endl; | |
33 | } | |
29 | m_regFilePath = GetUserFilePath() + REGISTRY_NAME; | |
30 | return m_regFilePath.c_str(); | |
34 | 31 | } |
35 | 32 | |
36 | 33 | // Simple POSIX file copy |