/[winpt]/trunk/Src/wptRegistryMobile.cpp
ViewVC logotype

Annotation of /trunk/Src/wptRegistryMobile.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 270 - (hide annotations)
Sat Oct 21 18:08:57 2006 UTC (18 years, 4 months ago) by twoaday
File size: 7270 byte(s)


1 twoaday 270 /* wptRegistryMobile.cpp - Mobile config access
2     * Copyright (C) 2006 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     * General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20     #ifdef HAVE_CONFIG_H
21     #include <config.h>
22     #endif
23    
24     #ifdef WINPT_MOBILE
25     #include <windows.h>
26    
27     #include "wptTypes.h"
28     #include "wptGPG.h"
29     #include "wptRegistry.h"
30     #include "wptHotkey.h"
31     #include "wptW32API.h"
32     #include "wptErrors.h"
33    
34     static config_file_t pr = NULL;
35    
36     struct winpt_prefs_s reg_prefs;
37    
38     /* Because we do not use any existing software, we hardcode
39     the return to FALSE. */
40     int is_gpg4win_installed (void)
41     {
42     return 0;
43     }
44    
45     /* XXX: the settings should be stored as 'winpt_prefs.txt'
46     because in mobile mode all files should be localted
47     in the same directory. */
48    
49     void
50     free_reg_prefs (void)
51     {
52     if (pr != NULL) {
53     commit_config ("c:\\winpt_prefs.txt", &pr);
54     release_config (pr);
55     }
56     pr = NULL;
57     }
58    
59    
60     static gpg_option_t
61     reg_find_option (const char *key)
62     {
63     if (pr == NULL)
64     parse_config ("c:\\winpt_prefs.txt", &pr);
65     return find_option (pr, key);
66     }
67    
68    
69     int
70     set_reg_winpt_prefs (winpt_prefs_t opt)
71     {
72     char buf[128];
73     size_t i;
74     int rc = 0;
75    
76     if (pr == NULL)
77     new_config (&pr);
78    
79     for (i=1; i < DIM (cfg); i++) {
80     switch (i) {
81     case CFG_CACHETIME:
82     sprintf (buf, "%d", opt->cache_time);
83     break;
84     case CFG_WORDWRAP:
85     sprintf (buf, "%d", opt->word_wrap);
86     break;
87     case CFG_WIPEMODE:
88     sprintf (buf, "%d", opt->wipe_mode);
89     break;
90     case CFG_FILEEXT:
91     sprintf (buf, "%d", opt->default_ext);
92     break;
93     case CFG_NOZIP_MMEDIA:
94     sprintf (buf, "%d", opt->no_zip_mmedia);
95     break;
96     case CFG_VIEWER:
97     sprintf (buf, "%d", opt->use_viewer);
98     break;
99     case CFG_ALWAYSTRUST:
100     sprintf (buf, "%d", opt->always_trust);
101     break;
102     case CFG_AUTOBACKUP:
103     sprintf (buf, "%d", opt->auto_backup);
104     break;
105     case CFG_AUTOBAKMODE:
106     sprintf (buf, "%d", opt->backup.mode);
107     break;
108     case CFG_DISHOTKEYS:
109     sprintf (buf, "%d", opt->no_hotkeys);
110     break;
111     case CFG_EXPERT:
112     sprintf (buf, "%d", opt->expert);
113     break;
114    
115     case CFG_FM_PROGRESS:
116     sprintf (buf, "%d", opt->fm.progress);
117     break;
118    
119     case CFG_BACKUP_INC_SKR:
120     sprintf (buf, "%d", opt->backup.include_secr);
121     break;
122     }
123     add_entry (pr, ENTRY_MULTI, cfg[i], buf);
124     }
125    
126     if (opt->backup.path != NULL)
127     add_entry (pr, ENTRY_MULTI, "BackupPath", opt->backup.path);
128    
129     for (i=0; wpt_hotkeys[i].name; i++) {
130     if (wpt_hotkeys[i].enabled) {
131     buf[0] = wpt_hotkeys[i].key;
132     buf[1] = 0;
133     add_entry (pr, ENTRY_MULTI, wpt_hotkeys[i].name, buf);
134     }
135     }
136    
137     return 0;
138     }
139    
140    
141     /* Retrieve the winpt preferences from the registry. */
142     int
143     get_reg_winpt_prefs (winpt_prefs_t opt)
144     {
145     gpg_option_t val;
146     size_t i;
147    
148     for (i=1; i < DIM (cfg); i++) {
149     val = reg_find_option (cfg[i]);
150     if (!val)
151     continue;
152     switch (i) {
153     case CFG_CACHETIME:
154     opt->cache_time = atoi (val->val);
155     break;
156     case CFG_WORDWRAP:
157     opt->word_wrap = atoi (val->val);
158     break;
159     case CFG_FILEEXT:
160     opt->default_ext = atoi (val->val);
161     break;
162     case CFG_NOZIP_MMEDIA:
163     opt->no_zip_mmedia = atoi (val->val);
164     break;
165     case CFG_VIEWER:
166     opt->use_viewer = atoi (val->val);
167     break;
168     case CFG_WIPEMODE:
169     opt->wipe_mode = atoi (val->val);
170     break;
171     case CFG_DISHOTKEYS:
172     opt->no_hotkeys = atoi (val->val);
173     break;
174     case CFG_ALWAYSTRUST:
175     opt->always_trust = atoi (val->val);
176     break;
177     case CFG_AUTOBACKUP:
178     opt->auto_backup = atoi (val->val);
179     break;
180     case CFG_AUTOBAKMODE:
181     opt->backup.mode = atoi (val->val);
182     break;
183     case CFG_EXPERT:
184     opt->expert = atoi (val->val);
185     break;
186     case CFG_FM_PROGRESS:
187     opt->fm.progress = atoi (val->val);
188     break;
189    
190     case CFG_BACKUP_INC_SKR:
191     opt->backup.include_secr = atoi (val->val);
192     break;
193     }
194     }
195    
196     val = reg_find_option("BackupPath");
197     if (val != NULL)
198     opt->backup.path = m_strdup (val->val);
199    
200     for (i=0; wpt_hotkeys[i].name; i++) {
201     wpt_hotkeys[i].enabled = 0;
202     val = reg_find_option (wpt_hotkeys[i].name);
203     if (val != NULL && val->val && val->val[0] != ' ') {
204     wpt_hotkeys[i].key = *val->val;
205     wpt_hotkeys[i].enabled = 1;
206     }
207     }
208     return 0;
209     }
210    
211    
212    
213     int
214     regist_inst_gnupg (int create_mokey)
215     {
216     return 0;
217     }
218    
219    
220    
221     int
222     regist_inst_winpt (int with_ext, int *created)
223     {
224     return 0;
225     }
226    
227    
228     char*
229     get_reg_entry (HKEY root_key, const char *dir, const char *key)
230     {
231     gpg_option_t val;
232    
233     val = reg_find_option (key);
234     if (!val)
235     return NULL;
236     return m_strdup (val->val);
237     }
238    
239    
240     int
241     set_reg_entry (HKEY root_key, const char *dir, const char *key,
242     const char *value)
243     {
244     modify_entry (pr, ENTRY_MULTI, key, value);
245     return 0;
246     }
247    
248    
249     int
250     set_reg_key (HKEY root_key, const char *dir, const char *key,
251     const char *value)
252     {
253    
254     set_reg_entry (root_key, dir, key, value);
255     return 0;
256     }
257    
258    
259     int
260     set_reg_entry_gpg (const char *key, const char *value)
261     {
262    
263     return set_reg_entry (HKEY_CURRENT_USER, NULL, key, value);
264     }
265    
266    
267     int
268     set_reg_entry_mo (const char *value)
269     {
270     return set_reg_entry (HKEY_CURRENT_USER, NULL, "MODir", value);
271     }
272    
273    
274     char*
275     get_reg_entry_gpg (const char *key)
276     {
277     gpg_option_t val;
278    
279     val = reg_find_option (key);
280     if (!val)
281     return NULL;
282     return m_strdup (val->val);
283     }
284    
285    
286     char*
287     get_reg_entry_gpg4win (const char *path)
288     {
289     return NULL;
290     }
291    
292    
293     char*
294     get_reg_entry_mo (void)
295     {
296     gpg_option_t val;
297    
298     val = reg_find_option ("MODir");
299     if (val != NULL)
300     return m_strdup (val->val);
301     return NULL;
302     }
303    
304    
305     int
306     set_reg_winpt_single (int id, int val)
307     {
308     char buf[64];
309     int rc;
310    
311     _snprintf (buf, DIM (buf)-1, "%d", val);
312     rc = set_reg_entry (HKEY_CURRENT_USER, NULL, cfg[id], buf);
313     return rc;
314     }
315    
316    
317     int
318     get_reg_winpt_single (int id)
319     {
320     char *buf;
321     int val = 0;
322    
323     buf = get_reg_entry (HKEY_CURRENT_USER, NULL, cfg[id]);
324     if (buf && *buf != ' ')
325     val = 1;
326     else if (!buf)
327     val = -1;
328     free_if_alloc (buf);
329     return val;
330     }
331    
332    
333    
334     int
335     set_reg_winpt_flag (const char *name, int val)
336     {
337     return set_reg_entry (HKEY_CURRENT_USER, NULL, name, val? "1" : "0");
338     }
339    
340    
341     int
342     get_reg_winpt_flag (const char *name)
343     {
344     char *buf;
345     int flag = 0;
346    
347     buf = get_reg_entry (HKEY_CURRENT_USER, NULL, name);
348     if (buf && buf[0] == '1')
349     flag = 1;
350     else if (!buf || buf && buf[0] != '0')
351     flag = -1;
352     free_if_alloc (buf);
353     return flag;
354     }
355    
356    
357     char*
358     get_reg_entry_keyserver (const char *name)
359     {
360     return get_reg_entry (HKEY_CURRENT_USER, NULL, name);
361     }
362    
363    
364     int
365     set_reg_entry_keyserver (const char *name, const char *val)
366     {
367     return set_reg_entry (HKEY_CURRENT_USER, NULL, name, val);
368     }
369     #endif

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26