This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
View Resources\changelog.txt for changes
- Loading branch information
abluescarab
committed
Mar 1, 2014
1 parent
fa2ef3b
commit 5e8854c
Showing
59 changed files
with
3,808 additions
and
2,150 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Data.SqlServerCe; | ||
using System.Diagnostics; | ||
using System.IO; | ||
//using System.Linq; | ||
//using System.Security.Policy; | ||
//using System.Security.Principal; | ||
//using System.Security.AccessControl; | ||
using System.Security; | ||
using System.Security.Permissions; | ||
//using System.Text; | ||
//using System.Windows.Forms; | ||
|
||
namespace Switchex { | ||
public class Globals { | ||
public static frmError frmError = new frmError(); | ||
|
||
public static List<Profile> profiles = new List<Profile>(); | ||
|
||
public enum FileAction { | ||
CreateFolder, | ||
DeleteFolder, | ||
CreateFile, | ||
WriteFile, | ||
CopyFile, | ||
DeleteFile, | ||
CreateBoth | ||
}; | ||
|
||
public static bool blnUpdates = false, | ||
resetSettings = false; | ||
public static int rowCount = 0; | ||
public static string | ||
downloadVersion = null, | ||
selectedID = null, | ||
selectedName = null, | ||
selectedIP = null, | ||
selectedWebsite = null, | ||
selectedPatch = null, | ||
selectedRating = null, | ||
selectedNotes = null, | ||
selectedProfile = null, | ||
currentProfile = null, | ||
changelogFile = System.Windows.Forms.Application.StartupPath + "\\Resources\\changelog.txt", | ||
helpFile = System.Windows.Forms.Application.StartupPath + "\\Resources\\Switchex Help.html"; | ||
|
||
public static int RunActionsExecutable(FileAction action, string[] args) { | ||
Process p = new Process(); | ||
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | ||
p.StartInfo.FileName = "fileactions.exe"; | ||
p.StartInfo.UseShellExecute = true; | ||
|
||
try { | ||
switch(action) { | ||
case FileAction.WriteFile: | ||
// args: change "path\to\file" "text to write" | ||
// note: can only be a text file (any extension) | ||
p.StartInfo.Arguments = "write \"" + args[0] + "\" \"\"" + args[1] + "\"\""; | ||
break; | ||
case FileAction.CreateBoth: | ||
// args: create both "path\to\folder" "path\to\file" ["text to write"] | ||
p.StartInfo.Arguments = "create both \"" + args[0] + "\" \"" + args[1] + "\""; | ||
|
||
if(args.Length > 2 && args[2] != null) { | ||
p.StartInfo.Arguments += " \"\"" + args[2] + "\"\""; | ||
} | ||
break; | ||
case FileAction.CreateFile: | ||
// args: create file "path\to\file" ["text to write"] | ||
// note: ["text to write"] is for text files (any extension) | ||
p.StartInfo.Arguments = "create file \"" + args[0] + "\""; | ||
|
||
if(args.Length > 1 && args[1] != null) { | ||
p.StartInfo.Arguments += " \"\"" + args[1] + "\"\""; | ||
} | ||
break; | ||
case FileAction.CreateFolder: | ||
// args: create folder "path\to\create" | ||
p.StartInfo.Arguments = "create folder \"" + args[0] + "\""; | ||
break; | ||
case FileAction.DeleteFile: | ||
// args: delete file "path\to\file" | ||
p.StartInfo.Arguments = "delete file \"" + args[0] + "\""; | ||
break; | ||
case FileAction.DeleteFolder: | ||
// args: delete folder "path\to\delete" | ||
p.StartInfo.Arguments = "delete folder \"" + args[0] + "\""; | ||
break; | ||
case FileAction.CopyFile: | ||
// args: copy "true/false" (delete source file) "file\to\copy" "path\to\new\location" | ||
p.StartInfo.Arguments = "copy " + args[0] + " \"" + args[1] + "\" \"" + args[2] + "\""; | ||
break; | ||
} | ||
|
||
p.Start(); | ||
p.WaitForExit(); | ||
|
||
if(p.ExitCode == 1) { | ||
p.StartInfo.Verb = "runas"; | ||
p.Start(); | ||
p.WaitForExit(); | ||
|
||
if(p.ExitCode != 0) { | ||
return -1; | ||
} | ||
} | ||
|
||
return p.ExitCode; | ||
} | ||
catch(Exception ex) { | ||
if(ex.Message.Contains("canceled by the user")) { | ||
return 5; | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get all profiles and add them to a global list. | ||
/// </summary> | ||
public static void GetProfiles() { | ||
profiles.Clear(); | ||
|
||
try { | ||
using(SqlCeConnection conn = new SqlCeConnection(Properties.Settings.Default.switchexConnectionString)) { | ||
using(SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM Profiles", conn)) { | ||
using(DataSet ds = new DataSet()) { | ||
using(SqlCeDataAdapter adapter = new SqlCeDataAdapter(cmd)) { | ||
adapter.SelectCommand = cmd; | ||
|
||
adapter.Fill(ds); | ||
|
||
foreach(DataRow row in ds.Tables[0].Rows) { | ||
profiles.Add(new Profile(false, Convert.ToInt32(row.ItemArray[0]))); | ||
} | ||
|
||
Globals.profiles.Sort((x, y) => x.ProfileName.CompareTo(y.ProfileName)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch(Exception ex) { | ||
Globals.frmError.ShowDialog(ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Data.SqlServerCe; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows.Forms; | ||
|
||
namespace Switchex { | ||
public class Profile { | ||
public static int newProfileID { get; set; } | ||
|
||
public string ProfileName { get; set; } | ||
public string ProfilePath { get; set; } | ||
public string ProfileDesc { get; set; } | ||
public int ProfileType { get; set; } | ||
public bool ProfileDefault { get; set; } | ||
public int ProfileID { get; set; } | ||
|
||
public Profile(bool isNew, int id) { | ||
try { | ||
using(SqlCeConnection conn = new SqlCeConnection(Properties.Settings.Default.switchexConnectionString)) { | ||
using(SqlCeCommand cmd = new SqlCeCommand("", conn)) { | ||
if(isNew) { | ||
int nextNew = 1; | ||
|
||
conn.Open(); | ||
|
||
foreach(Profile profile in Globals.profiles) { | ||
if(profile.ProfileName.Contains("New Profile ") && profile.ProfileName.Length >= 13) { | ||
if(Convert.ToInt32(profile.ProfileName.Substring(12)) == nextNew) { | ||
nextNew = Convert.ToInt32(profile.ProfileName.Substring(12)) + 1; | ||
} | ||
} | ||
} | ||
|
||
ProfileName = "New Profile " + nextNew; | ||
ProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); | ||
ProfileDesc = "A blank profile."; | ||
ProfileType = 32; | ||
|
||
cmd.CommandText = "INSERT INTO Profiles (ProfileName, ProfilePath, ProfileDescription, ProfileType) " + | ||
"VALUES (@name, @path, @desc, @type)"; | ||
|
||
cmd.Parameters.AddWithValue("@name", ProfileName); | ||
cmd.Parameters.AddWithValue("@path", ProfilePath); | ||
cmd.Parameters.AddWithValue("@desc", ProfileDesc); | ||
cmd.Parameters.AddWithValue("@type", ProfileType); | ||
cmd.ExecuteNonQuery(); | ||
|
||
cmd.CommandText = "SELECT @@IDENTITY"; | ||
ProfileID = Convert.ToInt32(cmd.ExecuteScalar()); | ||
} | ||
else { | ||
cmd.CommandText = "SELECT * FROM Profiles WHERE ID=@id"; | ||
cmd.Parameters.AddWithValue("@id", id); | ||
|
||
using(DataSet ds = new DataSet()) { | ||
using(SqlCeDataAdapter adapter = new SqlCeDataAdapter(cmd)) { | ||
adapter.SelectCommand = cmd; | ||
|
||
adapter.Fill(ds); | ||
|
||
foreach(DataRow row in ds.Tables[0].Rows) { | ||
ProfileID = Convert.ToInt32(row.ItemArray[0]); | ||
ProfileName = row.ItemArray[1].ToString(); | ||
ProfilePath = row.ItemArray[2].ToString(); | ||
ProfileDesc = row.ItemArray[3].ToString(); | ||
ProfileType = Convert.ToInt32(row.ItemArray[4]); | ||
ProfileDefault = (bool)row.ItemArray[5]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch(Exception ex) { | ||
Globals.frmError.ShowDialog(ex); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Edit the profile. | ||
/// </summary> | ||
/// <param name="id">The ID of the profile</param> | ||
/// <param name="name">The name of the profile (Optional)</param> | ||
/// <param name="path">The path of the profile (Optional)</param> | ||
/// <param name="desc">The description of the profile (Optional)</param> | ||
/// <param name="type">The type of profile (Optional)</param> | ||
/// <param name="isDefault">If the profile is the default or not (Optional)</param> | ||
public void EditProfile(int id, string name = null, string path = null, string desc = null, int type = 0, bool isDefault = false) { | ||
string oldName = null; | ||
|
||
if(name != null) { | ||
oldName = ProfileName; | ||
ProfileName = name; | ||
} | ||
if(path != null) | ||
ProfilePath = path; | ||
if(desc != null) | ||
ProfileDesc = desc; | ||
if(type != 0) | ||
ProfileType = type; | ||
ProfileDefault = isDefault; | ||
|
||
try { | ||
using(SqlCeConnection conn = new SqlCeConnection(Properties.Settings.Default.switchexConnectionString)) { | ||
using(SqlCeCommand cmd = new SqlCeCommand("UPDATE Profiles SET ProfileName=@name, ProfilePath=@path, ProfileDescription=@desc, " + | ||
"ProfileType=@type, ProfileDefault=@default WHERE ID=@id", conn)) { | ||
cmd.Parameters.AddWithValue("@name", ProfileName); | ||
cmd.Parameters.AddWithValue("@path", ProfilePath); | ||
cmd.Parameters.AddWithValue("@desc", ProfileDesc); | ||
cmd.Parameters.AddWithValue("@type", ProfileType); | ||
cmd.Parameters.AddWithValue("@default", (ProfileDefault ? 1 : 0)); | ||
cmd.Parameters.AddWithValue("@id", id); | ||
|
||
conn.Open(); | ||
cmd.ExecuteNonQuery(); | ||
|
||
if(name != null && oldName != null) { | ||
cmd.CommandText = "UPDATE Servers SET ServerProfile=@name WHERE ServerProfile=@old"; | ||
cmd.Parameters.AddWithValue("@old", oldName); | ||
|
||
cmd.ExecuteNonQuery(); | ||
} | ||
} | ||
} | ||
} | ||
catch(Exception ex) { | ||
Globals.frmError.ShowDialog(ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace Switchex { | ||
static class Program { | ||
public static bool keepRunning { get; set; } | ||
|
||
/// <summary> | ||
/// The main entry point for the application. | ||
/// </summary> | ||
[STAThread] | ||
static void Main() { | ||
Application.EnableVisualStyles(); | ||
Application.SetCompatibleTextRenderingDefault(false); | ||
Application.Run(new frmMain()); | ||
|
||
keepRunning = true; | ||
while(keepRunning) { | ||
keepRunning = false; | ||
Application.Run(new frmMain()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.