]> cygwin.com Git - cygwin-apps/setup.git/blame - ConnectionSetting.cc
(Fixing erroneous previous commit to ChangeLog):
[cygwin-apps/setup.git] / ConnectionSetting.cc
CommitLineData
39b42ff3
RC
1/*
2 * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins.
13 *
14 */
15
16#if 0
17static const char *cvsid =
18 "\n%%% $Id$\n";
19#endif
20
21#include "ConnectionSetting.h"
22#include "UserSettings.h"
23#include "io_stream.h"
071f7af3 24#include "netio.h"
39b42ff3
RC
25#include "resource.h"
26#include "String++.h"
27
28void
29ConnectionSetting::load()
30{
31 static int inited = 0;
32 if (inited)
33 return;
34 io_stream *f = UserSettings::Instance().settingFileForLoad("last-connection");
35 if (f)
36 {
37 char localdir[1000];
38 char *fg_ret = f->gets (localdir, 1000);
39b42ff3 39 if (fg_ret)
071f7af3 40 NetIO::net_method = typeFromString(fg_ret);
1622a084
RC
41 fg_ret = f->gets (localdir, 1000);
42 if (fg_ret)
071f7af3 43 NetIO::net_proxy_host = strdup(fg_ret);
1622a084
RC
44 fg_ret = f->gets (localdir, 1000);
45 if (fg_ret)
071f7af3 46 NetIO::net_proxy_port = atoi(fg_ret);
1622a084 47 delete f;
39b42ff3
RC
48 }
49 inited = 1;
50}
51
52void
53ConnectionSetting::save()
54{
1622a084 55 char port_str[20];
39b42ff3
RC
56
57 io_stream *f = UserSettings::Instance().settingFileForSave("last-connection");
58 if (f)
59 {
071f7af3 60 switch (NetIO::net_method) {
39b42ff3
RC
61 case IDC_NET_DIRECT:
62 f->write("Direct\n",7);
63 break;
64 case IDC_NET_IE5:
65 f->write("IE\n",3);
66 break;
67 case IDC_NET_PROXY:
68 f->write("Proxy\n",6);
071f7af3
MB
69 f->write(NetIO::net_proxy_host, strlen(NetIO::net_proxy_host));
70 sprintf(port_str, "\n%d\n", NetIO::net_proxy_port);
71 f->write(port_str, strlen(port_str));
39b42ff3
RC
72 break;
73 default:
74 break;
75 }
76 delete f;
77 }
78}
79
80int
08678720 81ConnectionSetting::typeFromString(const std::string& aType)
39b42ff3 82{
afa76033 83 if (!casecompare(aType, "Direct"))
39b42ff3 84 return IDC_NET_DIRECT;
afa76033 85 if (!casecompare(aType, "IE"))
39b42ff3 86 return IDC_NET_IE5;
afa76033 87 if (!casecompare(aType, "Proxy"))
39b42ff3
RC
88 return IDC_NET_PROXY;
89
90 /* A sanish default */
91 return IDC_NET_IE5;
92}
This page took 0.036879 seconds and 5 git commands to generate.