git @ Cat's Eye Technologies linapple / no-changedir
Remove support for, and need for, changing directory in-process. Chris Pressey 3 years ago
5 changed file(s) with 9 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
00 #pragma once
11
2 // configuration file
3 #define REGISTRY "linapple.conf"
42 extern FILE * registry; // our opened file
53
64 BOOL RegLoadString (LPCTSTR,LPCTSTR,BOOL,char**,DWORD);
66 #include <string>
77
88 #define USER_DIRECTORY_NAME "/linapple/"
9 #define REGISTRY_NAME "linapple.conf"
910 #define CONF_DIRECTORY_NAME "/conf/"
1011 #define SAVED_DIRECTORY_NAME "/saved/"
1112 #define FTP_DIRECTORY_NAME "/ftp/"
1920 Config();
2021 ~Config() {};
2122
22 void ChangeToUserDirectory();
2323 bool ValidateUserDirectory();
2424 bool CopyFile(std::string source, std::string dest);
2525 std::string GetUserFilePath();
26 std::string GetRegistryPath();
2627 protected:
2728 std::string GetHomePath();
2829 std::string GetInstallPath();
2930 private:
3031 std::string m_optsFilePath;
32 std::string m_regFilePath;
3133 };
3234
454454
455455 if(registry==NULL)
456456 {
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");
458458 return;
459459 }
460460 LOAD(TEXT("Computer Emulation"),&dwComputerType);
795795 // GPH: The very first thing we do is attempt to grab the needed configuration files and put them in the user's folder.
796796 Config config;
797797 config.ValidateUserDirectory();
798 config.ChangeToUserDirectory();
799
800798
801799 // reading FullScreen and Boot from conf file?
802800 bool bSetFullScreen = false;
803801 bool bBoot = false;
804802
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)
806804 spMono = fopen("speakersmono.pcm","wb");
807805 spStereo = fopen("speakersstereo.pcm","wb");
808806
178178
179179 void RegSaveKeyValue(char * NKey, char * NValue)
180180 {
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);
227182 }
228183
229184 //===========================================================================
2424 return m_optsFilePath.c_str();
2525 }
2626
27 void Config::ChangeToUserDirectory()
27 std::string Config::GetRegistryPath()
2828 {
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();
3431 }
3532
3633 // Simple POSIX file copy