Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit ab04035

Browse files
committed
Added SQLite DLL. Added database class. Changed exe locations to use SQLite instead of registry.
1 parent ab23b6c commit ab04035

6 files changed

+177
-39
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
SuperPutty/obj*
2-
bin*
2+
bin/*
3+
!bin/*.dll
4+
!bin/*.DLL
5+

SuperPutty/Classes/Database.cs

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Created by SharpDevelop.
3+
* User: Paul Hendryx
4+
* Date: 11/27/2010
5+
* Time: 10:25 AM
6+
*
7+
* To change this template use Tools | Options | Coding | Edit Standard Headers.
8+
*/
9+
using System;
10+
using System.Data;
11+
using System.Data.SQLite;
12+
using System.IO;
13+
using System.Windows.Forms;
14+
15+
using Microsoft.Win32;
16+
17+
namespace SuperPutty.Classes
18+
{
19+
/// <summary>
20+
/// Description of Database.
21+
/// </summary>
22+
public class Database
23+
{
24+
private SQLiteConnection _conn;
25+
26+
public Database()
27+
{
28+
}
29+
30+
public SQLiteConnection Open()
31+
{
32+
string db_filename = Application.StartupPath + "\\SuperPutty.db3";
33+
if (!File.Exists(db_filename))
34+
{
35+
SQLiteConnection.CreateFile(db_filename);
36+
}
37+
38+
string connection_string = "Data Source=" + db_filename + ";Version=3;";
39+
_conn = new System.Data.SQLite.SQLiteConnection(connection_string);
40+
_conn.Open();
41+
42+
UpgradeSchema();
43+
44+
return _conn;
45+
}
46+
47+
public string GetKey(string key)
48+
{
49+
SQLiteCommand cmd = new SQLiteCommand("select value from settings where key = '" + key + "';", _conn);
50+
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
51+
DataTable dt = new DataTable();
52+
da.Fill(dt);
53+
string value = "";
54+
if (dt.Rows.Count == 1)
55+
{
56+
value = (string)dt.Rows[0][0];
57+
}
58+
59+
return value;
60+
}
61+
62+
public void SetKey(string key, string value)
63+
{
64+
SQLiteCommand cmd = new SQLiteCommand("select id from settings where key = '" + key + "'", _conn);
65+
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
66+
DataTable dt = new DataTable();
67+
da.Fill(dt);
68+
69+
if (dt.Rows.Count == 0)
70+
{
71+
cmd.CommandText = "insert into settings (key, value) values ('" + key + "', '" + value + "')";
72+
}
73+
else
74+
{
75+
cmd.CommandText = "update settings set value = '" + value + "' where key = '" + key + "'";
76+
}
77+
cmd.ExecuteNonQuery();
78+
}
79+
80+
81+
82+
private void UpgradeSchema()
83+
{
84+
// Settings table
85+
if (_conn.GetSchema("Tables").Select("Table_Name = 'settings'").Length == 0)
86+
{
87+
SQLiteCommand cmd = new SQLiteCommand("create table if not exists settings(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, key varchar(255), value varchar(255));", _conn);
88+
cmd.ExecuteNonQuery();
89+
90+
cmd.CommandText = "insert into settings (key, value) values ('db_version', '1.0.1');";
91+
cmd.ExecuteNonQuery();
92+
}
93+
94+
// Settings table
95+
if (_conn.GetSchema("Tables").Select("Table_Name = 'sessions'").Length == 0)
96+
{
97+
string sql = "create table if not exists sessions (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, auto_start boolean, host varchar(255), last_dock integer, ";
98+
sql += "last_path varchar(255), port integer, proto varchar(255), putty_session varchar(255));";
99+
SQLiteCommand cmd = new SQLiteCommand(sql, _conn);
100+
cmd.ExecuteNonQuery();
101+
}
102+
103+
// Version Changes
104+
switch (GetKey("db_version"))
105+
{
106+
case "1.0.1":
107+
SetKey("db_version", "1.0.2");
108+
break;
109+
}
110+
}
111+
112+
private void upgrade_1_0_1_to_1_0_2()
113+
{
114+
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Jim Radford\SuperPuTTY\Settings");
115+
if (key != null)
116+
{
117+
string puttyExe = key.GetValue("PuTTYExe", "").ToString();
118+
if (File.Exists(puttyExe))
119+
{
120+
SetKey("putty_exe", puttyExe);
121+
}
122+
123+
string pscpExe = key.GetValue("PscpExe", "").ToString();
124+
if (File.Exists(pscpExe))
125+
{
126+
SetKey("pscp_exe", pscpExe);
127+
}
128+
}
129+
130+
}
131+
}
132+
}

SuperPutty/SuperPutty.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
</PropertyGroup>
4848
<ItemGroup>
4949
<Reference Include="System" />
50+
<Reference Include="System.Data.SQLite">
51+
<HintPath>..\bin\System.Data.SQLite.DLL</HintPath>
52+
</Reference>
5053
<Reference Include="System.Web" />
5154
<Reference Include="System.Data" />
5255
<Reference Include="System.Deployment" />
@@ -65,6 +68,7 @@
6568
<Compile Include="AboutBox1.Designer.cs">
6669
<DependentUpon>AboutBox1.cs</DependentUpon>
6770
</Compile>
71+
<Compile Include="Classes\Database.cs" />
6872
<Compile Include="ctlApplicationPanel.cs">
6973
<SubType>Component</SubType>
7074
</Compile>
@@ -192,6 +196,9 @@
192196
<DependentUpon>ToolWindow.cs</DependentUpon>
193197
</Compile>
194198
</ItemGroup>
199+
<ItemGroup>
200+
<Folder Include="Classes" />
201+
</ItemGroup>
195202
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
196203
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
197204
Other similar extension points exist, see Microsoft.Common.targets.

SuperPutty/frmSuperPutty.Designer.cs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SuperPutty/frmSuperPutty.cs

+33-38
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,27 @@
3030
using System.Runtime.InteropServices;
3131
using System.Text;
3232
using System.Windows.Forms;
33-
3433
using Microsoft.Win32;
3534
using WeifenLuo.WinFormsUI.Docking;
35+
using System.Data.SQLite;
3636

3737
namespace SuperPutty
3838
{
3939
public partial class frmSuperPutty : Form
4040
{
4141
private static string _PuttyExe;
42-
4342
public static string PuttyExe
4443
{
4544
get { return _PuttyExe; }
46-
set
47-
{
48-
_PuttyExe = value;
49-
50-
if (File.Exists(value))
51-
{
52-
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Jim Radford\SuperPuTTY\Settings");
53-
key.SetValue("PuTTYExe", value);
54-
}
55-
}
45+
set { _PuttyExe = value; }
5646
}
5747

5848
private static string _PscpExe;
5949

6050
public static string PscpExe
6151
{
6252
get { return _PscpExe; }
63-
set
64-
{
65-
_PscpExe = value;
66-
67-
if (File.Exists(value))
68-
{
69-
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Jim Radford\SuperPuTTY\Settings");
70-
key.SetValue("PscpExe", value);
71-
}
72-
}
53+
set { _PscpExe = value; }
7354
}
7455

7556
public static bool IsScpEnabled
@@ -78,33 +59,35 @@ public static bool IsScpEnabled
7859
}
7960

8061
private SessionTreeview m_Sessions;
81-
62+
private Classes.Database m_db;
63+
8264
public frmSuperPutty(string[] args)
8365
{
84-
// Get Registry Entry for Putty Exe
85-
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Jim Radford\SuperPuTTY\Settings");
86-
if (key != null)
66+
// Check SQLite Database
67+
openOrCreateSQLiteDatabase();
68+
69+
#region Exe Paths
70+
// Get putty executable path
71+
if (File.Exists(this.m_db.GetKey("putty_exe")))
8772
{
88-
string puttyExe = key.GetValue("PuTTYExe", "").ToString();
89-
if (File.Exists(puttyExe))
90-
{
91-
PuttyExe = puttyExe;
92-
}
73+
PuttyExe = this.m_db.GetKey("putty_exe");
74+
}
9375

94-
string pscpExe = key.GetValue("PscpExe", "").ToString();
95-
if (File.Exists(pscpExe))
96-
{
97-
PscpExe = pscpExe;
98-
}
76+
// Get pscp executable path
77+
if (File.Exists(this.m_db.GetKey("pscp_exe")))
78+
{
79+
PscpExe = this.m_db.GetKey("pscp_exe");
9980
}
10081

10182
if (String.IsNullOrEmpty(PuttyExe))
10283
{
10384
dlgFindPutty dialog = new dlgFindPutty();
10485
if (dialog.ShowDialog() == DialogResult.OK)
10586
{
106-
PuttyExe = dialog.PuttyLocation;
107-
PscpExe = dialog.PscpLocation;
87+
this.m_db.SetKey("putty_exe", dialog.PuttyLocation);
88+
this.m_db.SetKey("pscp_exe", dialog.PscpLocation);
89+
PuttyExe = this.m_db.GetKey("putty_exe");
90+
PscpExe = this.m_db.GetKey("pscp_exe");
10891
}
10992
}
11093

@@ -115,6 +98,7 @@ public frmSuperPutty(string[] args)
11598
Application.Exit();
11699
System.Environment.Exit(1);
117100
}
101+
#endregion
118102

119103
InitializeComponent();
120104

@@ -511,5 +495,16 @@ void ToolStripMenuItem4Click(object sender, EventArgs e)
511495
{
512496
Process.Start("http://superputty.vanillaforums.com/");
513497
}
498+
499+
void DockPanel1ActiveContentChanged(object sender, EventArgs e)
500+
{
501+
502+
}
503+
504+
private void openOrCreateSQLiteDatabase()
505+
{
506+
this.m_db = new SuperPutty.Classes.Database();
507+
this.m_db.Open();
508+
}
514509
}
515510
}

bin/System.Data.SQLite.DLL

884 KB
Binary file not shown.

0 commit comments

Comments
 (0)