static void Main(string[] args) { //Form initialization if (Environment.OSVersion.Version.Major >= 6) { SetProcessDPIAware(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Create the database, if it doesn't exist already, in the executable's folder AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ProgramExceptionHandler); if (!File.Exists(GetExeFolder() + "\\junctions.db")) { SQLiteConnection.CreateFile(GetExeFolder() + "\\junctions.db"); } //Create the table in the database, if it doesn't exist already SQLiteManager.ExecuteSQLiteCommand("CREATE TABLE IF NOT EXISTS junctions (origin VARCHAR(255), target VARCHAR(255));"); SQLiteManager.CloseConnection(); //Launch the main junction list form if no argument is supplied (launched directly or through start menu), //or launch the transfer form if a argument is supplied if (args.Length == 0) { Application.Run(new JunctionViewForm()); } else { Application.Run(new TransferForm(args[0])); } }
public TransferForm(string arg) { InitializeComponent(); //Select the confirm button by default ActiveControl = confirmButton; origin = arg; //Get any junctions that point to the folder being moved, and save where they were moved from if they exist SQLiteDataReader reader = SQLiteManager.ExecuteSQLiteCommand("SELECT origin, target FROM junctions WHERE target = '" + origin + "';"); string databaseOrigin = null; if (reader.Read()) { databaseOrigin = reader.GetString(reader.GetOrdinal("origin")); } reader.Close(); SQLiteManager.CloseConnection(); if (!JunctionPoint.Exists(origin)) { //If the directory given is not a junction and is registered in the database... if (databaseOrigin != null) { //Hide some elements to just show a message instead of getting input from the user junctionArg = true; destinationInput.Visible = false; browseButton.Visible = false; //Assign the variables their proper values target = origin; origin = databaseOrigin; //Give the user a message that this folder has been moved by this app, and ask if they want to move it back label1.Text = target + " is already moved from " + origin + "! Would you like to move it back?"; } else { //If the directory given is not a junction and isn't registered in the database... //Leave the window in its standard move with junction state, and put the last used location as the default junctionArg = false; destinationInput.Text = Program.GetLastStorage() + "\\" + new DirectoryInfo(origin).Name; } } else { //if the directory given is a junction //Hide some elements to just show a message instead of getting input from the user junctionArg = true; destinationInput.Visible = false; browseButton.Visible = false; //Get the directory the junction is pointing to and ask the user if he would like to move that folder back target = JunctionPoint.GetTarget(origin); label1.Text = "Move " + target + " back to its original location at " + origin + "?"; } }
private void refreshDataGrid() { SQLiteDataReader reader = SQLiteManager.ExecuteSQLiteCommand("SELECT * FROM junctions;"); List <string> sqlCommandQueue = new List <string>(); while (reader.Read()) { string origin = reader.GetString(reader.GetOrdinal("origin")); string target = reader.GetString(reader.GetOrdinal("target")); if (!JunctionPoint.Exists(origin)) { if (Directory.Exists(origin)) { MessageBox.Show("The junction at " + origin + " that pointed to " + target + " has been replaced by a folder by the same name. If you moved the folder back yourself this is fine, otherwise you might wanna look into this", "Junction is now a folder", MessageBoxButtons.OK); sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';"); Program.Log("WARNING: Junction at " + origin + " that pointed to " + target + " replaced by a folder with the same name"); continue; } else { MessageBox.Show("The junction at " + origin + " that pointed to " + target + " is not there, it could have been moved or deleted.", "Missing junction", MessageBoxButtons.OK); sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';"); Program.Log("WARNING: Junction at " + origin + " that pointed to " + target + " missing"); continue; } } string realTarget = JunctionPoint.GetTarget(origin); if (realTarget != target) { MessageBox.Show("The junction at " + origin + " has changed targets from " + target + " to " + realTarget + ".", "Moved junction target", MessageBoxButtons.OK); sqlCommandQueue.Add("UPDATE junctions SET target = '" + realTarget + "' WHERE origin = '" + origin + "';"); target = realTarget; Program.Log("WARNING: Junction at " + origin + " is now pointing to " + realTarget + ", was pointing to " + target); } if (!Directory.Exists(realTarget)) { MessageBox.Show("The folder at " + target + " is missing, the junction " + origin + " pointed to it.", "Folder missing", MessageBoxButtons.OK); JunctionPoint.Delete(origin); sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';"); Program.Log("WARNING: " + target + " is missing, pointed to by junction at " + origin); } } SQLiteManager.CloseConnection(); foreach (string s in sqlCommandQueue) { SQLiteManager.ExecuteSQLiteCommand(s); SQLiteManager.CloseConnection(); } SQLiteManager.CloseConnection(); //Create a DataSet object DataSet dataSet = new DataSet(); //Get the adapter for the grid view, which will contain every junction in the table SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT * FROM junctions;", SQLiteManager.GetSQLiteConnection()); dataAdapter.Fill(dataSet); //Fill the view with the dataset dataGridView1.DataSource = dataSet.Tables[0].DefaultView; //Close the connection SQLiteManager.CloseConnection(); if (dataGridView1.Rows.Count == 0) { restoreButton.Enabled = false; moveButton.Enabled = false; } else { restoreButton.Enabled = true; moveButton.Enabled = true; } }