mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge branch 'os-specific' of https://github.com/atmaxinger/OpenRCT2 into atmaxinger-os-specific
This commit is contained in:
commit
1321892024
43
src/config.c
43
src/config.c
|
@ -19,14 +19,12 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <shlobj.h>
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <SDL_keycode.h>
|
||||
#include <ctype.h>
|
||||
#include "addresses.h"
|
||||
#include "config.h"
|
||||
#include "rct2.h"
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
#include "osinterface.h"
|
||||
|
||||
|
@ -117,20 +115,20 @@ void config_reset_shortcut_keys()
|
|||
*/
|
||||
void config_load()
|
||||
{
|
||||
HANDLE hFile;
|
||||
DWORD bytesRead;
|
||||
FILE *fp=NULL;
|
||||
|
||||
char* path = get_file_path(PATH_ID_GAMECFG);
|
||||
hFile = CreateFile(get_file_path(PATH_ID_GAMECFG), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
||||
FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
|
||||
fp = fopen(path, "rb");
|
||||
|
||||
if (fp != NULL) {
|
||||
// Read and check magic number
|
||||
ReadFile(hFile, RCT2_ADDRESS(0x013CE928, void), 4, &bytesRead, NULL);
|
||||
fread(RCT2_ADDRESS(0x013CE928, void), 1, 4, fp);
|
||||
|
||||
if (RCT2_GLOBAL(0x013CE928, int) == MagicNumber) {
|
||||
// Read options
|
||||
ReadFile(hFile, (void*)0x009AAC5C, 2155, &bytesRead, NULL);
|
||||
CloseHandle(hFile);
|
||||
|
||||
fread((void*)0x009AAC5C, 1, 2155, fp);
|
||||
fclose(fp);
|
||||
|
||||
//general configuration
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, sint8) = gGeneral_config.edge_scrolling;
|
||||
|
@ -197,14 +195,12 @@ void config_load()
|
|||
*/
|
||||
void config_save()
|
||||
{
|
||||
HANDLE hFile;
|
||||
DWORD bytesWritten;
|
||||
|
||||
hFile = CreateFile(get_file_path(PATH_ID_GAMECFG), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
WriteFile(hFile, &MagicNumber, 4, &bytesWritten, NULL);
|
||||
WriteFile(hFile, (LPCVOID)0x009AAC5C, 2155, &bytesWritten, NULL);
|
||||
CloseHandle(hFile);
|
||||
FILE *fp=NULL;
|
||||
fp = fopen(get_file_path(PATH_ID_GAMECFG), "wb");
|
||||
if (fp != NULL){
|
||||
fwrite(&MagicNumber, 4, 1, fp);
|
||||
fwrite((void*)0x009AAC5C, 2155, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +250,7 @@ void config_init()
|
|||
static int config_find_rct2_path(char *resultPath)
|
||||
{
|
||||
int i;
|
||||
DWORD dwAttrib;
|
||||
|
||||
const char *searchLocations[] = {
|
||||
"C:\\Program Files\\Infogrames\\RollerCoaster Tycoon 2",
|
||||
"C:\\Program Files (x86)\\Infogrames\\RollerCoaster Tycoon 2",
|
||||
|
@ -266,8 +262,7 @@ static int config_find_rct2_path(char *resultPath)
|
|||
};
|
||||
|
||||
for (i = 0; i < countof(searchLocations); i++) {
|
||||
dwAttrib = GetFileAttributes(searchLocations[i]);
|
||||
if (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
if ( osinterface_directory_exists(searchLocations[i]) ) {
|
||||
strcpy(resultPath, searchLocations[i]);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include "rct2.h"
|
||||
#include <windows.h> // for MAX_PATH
|
||||
|
||||
enum {
|
||||
CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES = (1 << 0),
|
||||
|
|
|
@ -454,6 +454,11 @@ char *osinterface_get_orct2_homesubfolder(const char *subFolder)
|
|||
return path;
|
||||
}
|
||||
|
||||
int osinterface_file_exists(const char *path)
|
||||
{
|
||||
return !(GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
int osinterface_directory_exists(const char *path)
|
||||
{
|
||||
DWORD dwAttrib = GetFileAttributes(path);
|
||||
|
|
|
@ -52,6 +52,7 @@ char* osinterface_open_directory_browser(char *title);
|
|||
|
||||
char* osinterface_get_orct2_homefolder();
|
||||
char *osinterface_get_orct2_homesubfolder(const char *subFolder);
|
||||
int osinterface_file_exists(const char *path);
|
||||
int osinterface_directory_exists(const char *path);
|
||||
int osinterface_ensure_directory_exists(const char *path);
|
||||
|
||||
|
|
|
@ -189,8 +189,7 @@ void rct2_init()
|
|||
void rct2_init_directories()
|
||||
{
|
||||
// check install directory
|
||||
DWORD dwAttrib = GetFileAttributes(gGeneral_config.game_path);
|
||||
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
if ( !osinterface_directory_exists(gGeneral_config.game_path) ) {
|
||||
osinterface_show_messagebox("Invalid RCT2 installation path. Please correct in config.ini.");
|
||||
exit(-1);
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
#pragma pack(1)
|
||||
|
||||
#include <lodepng.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include "osinterface.h"
|
||||
#include "addresses.h"
|
||||
#include "config.h"
|
||||
|
@ -30,6 +30,8 @@
|
|||
#include "string_ids.h"
|
||||
#include "window_error.h"
|
||||
|
||||
#include <windows.h> // For MAX_PATH
|
||||
|
||||
|
||||
static int screenshot_dump_bmp();
|
||||
static int screenshot_dump_png();
|
||||
|
@ -75,8 +77,9 @@ static int screenshot_get_next_path(char *path, char *extension)
|
|||
// Glue together path and filename
|
||||
sprintf(path, "%s%cSCR%d%s", screenshotPath, osinterface_get_path_separator(), i, extension);
|
||||
|
||||
if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||
if (!osinterface_file_exists(path)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
free(screenshotPath);
|
||||
|
@ -129,22 +132,23 @@ int screenshot_dump_bmp()
|
|||
|
||||
int i, y, index, width, height, stride;
|
||||
char *buffer, path[MAX_PATH], *row;
|
||||
HANDLE hFile;
|
||||
DWORD bytesWritten;
|
||||
FILE *fp;
|
||||
unsigned int bytesWritten;
|
||||
|
||||
// Get a free screenshot path
|
||||
if ((index = screenshot_get_next_path(path, ".bmp")) == -1)
|
||||
return -1;
|
||||
|
||||
// Open file for writing
|
||||
hFile = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
// Open binary file for writing
|
||||
if ((fp = fopen(path, "wb")) == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate buffer
|
||||
buffer = malloc(0xFFFF);
|
||||
if (buffer == NULL) {
|
||||
CloseHandle(hFile);
|
||||
//CloseHandle(hFile);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -159,9 +163,9 @@ int screenshot_dump_bmp()
|
|||
header.bfSize = height * stride + 1038;
|
||||
header.bfOffBits = 1038;
|
||||
|
||||
WriteFile(hFile, &header, sizeof(header), &bytesWritten, NULL);
|
||||
if (bytesWritten != sizeof(header)) {
|
||||
CloseHandle(hFile);
|
||||
bytesWritten = fwrite(&header, sizeof(BitmapFileHeader), 1, fp);
|
||||
if (bytesWritten != 1) {
|
||||
fclose(fp);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
@ -176,9 +180,9 @@ int screenshot_dump_bmp()
|
|||
info.biYPelsPerMeter = 2520;
|
||||
info.biClrUsed = 246;
|
||||
|
||||
WriteFile(hFile, &info, sizeof(info), &bytesWritten, NULL);
|
||||
if (bytesWritten != sizeof(info)) {
|
||||
CloseHandle(hFile);
|
||||
bytesWritten=fwrite(&info, sizeof(BitmapInfoHeader), 1, fp);
|
||||
if (bytesWritten != 1) {
|
||||
fclose(fp);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
@ -190,9 +194,9 @@ int screenshot_dump_bmp()
|
|||
buffer[i * 4 + 2] = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 2];
|
||||
}
|
||||
|
||||
WriteFile(hFile, buffer, 246 * 4, &bytesWritten, NULL);
|
||||
if (bytesWritten != 246 * 4) {
|
||||
CloseHandle(hFile);
|
||||
bytesWritten = fwrite(buffer, sizeof(char), 246*4, fp);
|
||||
if (bytesWritten != 246*4){
|
||||
fclose(fp);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
@ -204,14 +208,14 @@ int screenshot_dump_bmp()
|
|||
memset(buffer, 0, stride);
|
||||
memcpy(buffer, row, dpi->width);
|
||||
|
||||
WriteFile(hFile, buffer, stride, &bytesWritten, NULL);
|
||||
if (bytesWritten != stride) {
|
||||
CloseHandle(hFile);
|
||||
bytesWritten=fwrite(buffer, sizeof(char), stride, fp);
|
||||
if (bytesWritten != stride){
|
||||
fclose(fp);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
fclose(fp);
|
||||
free(buffer);
|
||||
|
||||
return index;
|
||||
|
|
Loading…
Reference in New Issue