Ejemplo n.º 1
0
        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]));
            }
        }
Ejemplo n.º 2
0
        private void createButton_Click(object sender, EventArgs e)
        {
            string origin = junctionTextBox.Text;
            string target = targetTextBox.Text;

            if (origin.Length == 0)
            {
                ActiveControl = junctionTextBox;
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }
            else if (target.Length == 0)
            {
                ActiveControl = targetTextBox;
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            if (!Directory.Exists(target))
            {
                DialogResult recursionCaution = MessageBox.Show("There is no folder at " + target + ", please select a folder that the junction can target", "Folder doesn't exist", MessageBoxButtons.OK);
            }

            DialogResult confirmDialog = MessageBox.Show("Are you sure you want to create a junction at " + origin + " that links to " + target + "?", "Confirmation", MessageBoxButtons.YesNo);

            if (confirmDialog == DialogResult.No)
            {
                return;
            }

            JunctionPoint.Create(origin, target, true);

            SQLiteManager.AddJunction(origin, target);
        }
Ejemplo n.º 3
0
 public static void MoveReplaceJunction(string origin, string target)
 {
     //Delete the junction
     JunctionPoint.Delete(origin);
     //Copy the folder back and delete the original folder (essentially moving the function)
     Program.CopyFolder(target, origin);
     Directory.Delete(target, true);
     //Update the SQLite database with the removal of the junction
     SQLiteManager.RemoveJunction(origin);
     Program.Log("INFO: Moved " + target + " to " + origin);
 }
Ejemplo n.º 4
0
        public static void MoveWithJunction(string origin, string target)
        {
            //Copy folder and delete the original folder (essentially a move"
            Program.CopyFolder(origin, target);
            Directory.Delete(origin, true);

            Program.Log("INFO: Moved " + origin + " to " + target);
            //Create a junction at the original location pointing to the new location
            JunctionPoint.Create(origin, target, true);
            //Update the SQLite database with the new junction created
            SQLiteManager.AddJunction(origin, target);
        }
Ejemplo n.º 5
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 + "?";
            }
        }
Ejemplo n.º 6
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (junctionPathBox.Text.Length == 0)
     {
         ActiveControl = junctionPathBox;
         System.Media.SystemSounds.Exclamation.Play();
     }
     else
     {
         string origin = junctionPathBox.Text;
         if (JunctionPoint.Exists(origin))
         {
             string target = JunctionPoint.GetTarget(origin);
             SQLiteManager.AddJunction(origin, target);
             Close();
         }
     }
 }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
        private void confirmButton_Click(object sender, EventArgs e)
        {
            //If the destinatino box is empty, select it, play a tone, and quit the method
            if (destinationInput.Text.Length == 0)
            {
                ActiveControl = destinationInput;
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            //Warn the user if they are attempting to put the folder into the folder, which will lead to recursion
            if (destinationInput.Text == origin.Substring(0, origin.LastIndexOf('\\')))
            {
                DialogResult recursionCaution = MessageBox.Show("You're attempting to move a folder within itself, this will put this folder within itself forever until the path is to long.", "Recursion Warning", MessageBoxButtons.OK);
            }
            else if (destinationInput.Text == origin)
            {
                DialogResult recursionCaution = MessageBox.Show("You can't move a folder to where it currently is", "No Move Warning", MessageBoxButtons.OK);
            }
            else if (JunctionPoint.Exists(origin))
            {
                DialogResult recursionCaution = MessageBox.Show("Moving a junction isn't allowed, please restore the junction at " + origin + " first.", "Can't Move Junction", MessageBoxButtons.OK);
            }
            else
            {
                //If this form is not involving an existing junction...
                //Find the target by getting the input from the user
                target = destinationInput.Text;

                DialogResult confirmDialog = MessageBox.Show("Are you sure you want to move " + origin + " to " + target + " and update the junction at " + junction + " to point to it?", "Confirmation", MessageBoxButtons.YesNo);
                if (confirmDialog == DialogResult.No)
                {
                    return;
                }

                //If a directory already exists where the folder is going to be moved, ask the user if he is sure he wants to delete it
                if (Directory.Exists(target) && Directory.EnumerateFileSystemEntries(target).Any())
                {
                    //
                    DialogResult dialogResult = MessageBox.Show("There is already an existing folder at " + target + ", would you like to delete it?", "Existing Folder Found", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        Directory.Delete(target, true);
                    }
                    else
                    {
                        return;
                    }
                }

                //Enable an ambiguous loading indicator
                progressBar.Style = ProgressBarStyle.Marquee;

                //Move the folder and make a junction
                Program.CopyFolder(origin, target);
                Directory.Delete(origin, true);

                Program.Log("INFO: Moved " + origin + " to " + target);

                JunctionPoint.Create(junction, target, true);

                Program.Log("INFO: Updated junction at " + junction + " to point to " + target);

                SQLiteManager.ExecuteSQLiteCommand("UPDATE junctions SET target = '" + target + "' WHERE origin = '" + junction + "';");

                Close();
            }
        }