File: ini.cpp

package info (click to toggle)
pcsx2 1.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 28,464 kB
  • sloc: cpp: 299,796; ansic: 23,973; lisp: 2,689; asm: 908; perl: 852; sh: 789; xml: 116; makefile: 60
file content (132 lines) | stat: -rw-r--r-- 4,012 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*  OnePAD - author: arcum42(@gmail.com)
 *  Copyright (C) 2009
 *
 *  Based on ZeroPAD, author zerofrog@gmail.com
 *  Copyright (C) 2006-2007
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <string.h>

#include "GamePad.h"
#include "keyboard.h"
#include "onepad.h"

extern std::string s_strIniPath;

void DefaultKeyboardValues()
{
    set_keyboard_key(0, XK_a, PAD_L2);
    set_keyboard_key(0, XK_semicolon, PAD_R2);
    set_keyboard_key(0, XK_w, PAD_L1);
    set_keyboard_key(0, XK_p, PAD_R1);
    set_keyboard_key(0, XK_i, PAD_TRIANGLE);
    set_keyboard_key(0, XK_l, PAD_CIRCLE);
    set_keyboard_key(0, XK_k, PAD_CROSS);
    set_keyboard_key(0, XK_j, PAD_SQUARE);
    set_keyboard_key(0, XK_v, PAD_SELECT);
    set_keyboard_key(0, XK_n, PAD_START);
    set_keyboard_key(0, XK_e, PAD_UP);
    set_keyboard_key(0, XK_f, PAD_RIGHT);
    set_keyboard_key(0, XK_d, PAD_DOWN);
    set_keyboard_key(0, XK_s, PAD_LEFT);
}

void SaveConfig()
{
    FILE *f;

    const std::string iniFile(s_strIniPath + "OnePAD2.ini");
    f = fopen(iniFile.c_str(), "w");
    if (f == NULL) {
        printf("OnePAD: failed to save ini %s\n", iniFile.c_str());
        return;
    }

    fprintf(f, "first_time_wizard = %d\n", g_conf.ftw);
    fprintf(f, "log = %d\n", g_conf.log);
    fprintf(f, "options = %d\n", g_conf.packed_options);
    fprintf(f, "mouse_sensibility = %d\n", g_conf.get_sensibility());
    fprintf(f, "ff_intensity = %d\n", g_conf.get_ff_intensity());
    fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
    fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));

    for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
        for (auto const &it : g_conf.keysym_map[pad])
            fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second);

    for (auto const &it : g_conf.sdl2_mapping)
        fprintf(f, "SDL2 = %s\n", it.c_str());

    fclose(f);
}

void LoadConfig()
{
    FILE *f;
    bool have_user_setting = false;

    g_conf.init();

    const std::string iniFile(s_strIniPath + "OnePAD2.ini");
    f = fopen(iniFile.c_str(), "r");
    if (f == NULL) {
        printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
        SaveConfig(); //save and return
        return;
    }

    u32 value;

    if (fscanf(f, "first_time_wizard = %u\n", &value) == 1)
        g_conf.ftw = value;

    if (fscanf(f, "log = %u\n", &value) == 1)
        g_conf.log = value;

    if (fscanf(f, "options = %u\n", &value) == 1)
        g_conf.packed_options = value;

    if (fscanf(f, "mouse_sensibility = %u\n", &value) == 1)
        g_conf.set_sensibility(value);

    if (fscanf(f, "ff_intensity = %u\n", &value) == 1)
        g_conf.set_ff_intensity(value);

    size_t uid;
    if (fscanf(f, "uid[0] = %zu\n", &uid) == 1)
        g_conf.set_joy_uid(0, uid);
    if (fscanf(f, "uid[1] = %zu\n", &uid) == 1)
        g_conf.set_joy_uid(1, uid);

    u32 pad;
    u32 keysym;
    u32 index;
    while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) == 3) {
        set_keyboard_key(pad & 1, keysym, index);
        if (pad == 0)
            have_user_setting = true;
    }

    char sdl2[512];
    while (fscanf(f, "SDL2 = %511[^\n]\n", sdl2) == 1)
        g_conf.sdl2_mapping.push_back(std::string(sdl2));

    if (!have_user_setting)
        DefaultKeyboardValues();

    fclose(f);
}