/// <summary>
        /// load the change log and the snapshot and creates them if they dont exist
        /// </summary>
        /// <param name="pro"></param>
        public ModificationRecorder(Project pro)
        {
            try
            {
                this.pro = pro;
                logDirectory = new DirectoryInfo(pro.Location + @"\" + SettingsStore.Default.logFolderName);
                if (!logDirectory.Exists)
                {
                    logDirectory.Create();
                    logDirectory.Refresh();
                    logDirectory.Attributes = logDirectory.Attributes | FileAttributes.Hidden;
                }
                root = new RootFolder("", pro.Location, File.GetLastWriteTime(pro.Location));
                xmlPath = Path.Combine(logDirectory.FullName, "fileList.xml");
                if (File.Exists(xmlPath))
                {
                    try
                    {
                        using (XmlReader reader = XmlReader.Create(xmlPath))
                        {
                            root.load(reader);
                        }
                        System.Diagnostics.Debug.WriteLine(root.print());
                    }
                    catch
                    {

                    }
                }
                log = new changeLog(Path.Combine(logDirectory.FullName, "filelog.list"));
                pro.LastDate = log.getLastModTime();
            }
            catch
            {

            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// saves the changes to the project
        /// </summary>
        /// <param name="pro"></param>
        /// <returns></returns>
        private bool saveResults(Project pro)
        {
            bool wasMonitoring = false;
            if (pro.Location != null && !pro.Location.Equals(txtLocation.Text))
            {
                if (pro.ModrecorderCreated && pro.ModRecorder.isUpdating)
                {
                    MessageBox.Show("Unable to Change Location. Update is in progress please wait for the update to finish", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtLocation.Select();
                    return false;
                }
                else if (pro.isMonitoring)
                {
                    wasMonitoring = true;
                    pro.stopMonitoring();
                }

                try
                {
                    if (Directory.Exists(pro.Location))
                    {
                        if (Directory.GetDirectories(pro.Location).Length > 0 || Directory.GetFiles(pro.Location).Length > 0)
                        {
                            DialogResult res = MessageBox.Show("Do you want to move the contents of the previous location to the new location?", "Confim", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (res == DialogResult.Yes)
                            {
                                try
                                {
                                    copyDir(pro.Location, txtLocation.Text);
                                    Directory.Delete(pro.Location,true);
                                }
                                catch
                                {
                                    MessageBox.Show("Unable to Move Directory. Check location is valid and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    txtLocation.Select();
                                    return false;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Failed processing Directory check path is valid and try restarting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (!PathChanged)
            {
                try
                {
                    Directory.CreateDirectory(txtLocation.Text);
                    PathChanged = true;
                }
                catch
                {
                    MessageBox.Show("Unable to create Directory. Check location is valid and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtLocation.Select();
                    return false;
                }
            }
            else
            {
                if (!Directory.Exists(txtLocation.Text))
                {
                    DialogResult res = MessageBox.Show("Directory does not exist. Do you want to create the Directory?", "Confim", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (res == DialogResult.Yes)
                    {
                        try
                        {
                            Directory.CreateDirectory(txtLocation.Text);
                            PathChanged = true;
                        }
                        catch
                        {
                            MessageBox.Show("Unable to create Directory. Check location is valid and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtLocation.Select();
                            return false;
                        }

                    }
                    else
                    {
                        txtLocation.Select();
                        return false;
                    }
                }

            }

            pro.Name = txtName.Text;
            pro.Location = txtLocation.Text;
            pro.Description = txtDescription.Text;
            pro.Note = txtNotes.Text;
            pro.AutoMonitor = chkAutomatic.Checked;
            if (pro.NewEntry)
                pro.ModRecorder.updateChangeList += new EventHandler(ModRecorder_updateChangeList);

            if (excludeChanged)
            {
                List<string> excludeList = new List<string>();
                foreach (DataGridViewRow row in dgvExcludedFolders.Rows)
                {
                    if (!row.IsNewRow)
                        excludeList.Add(Convert.ToString(row.Cells[0].Value));
                }
                pro.ExcludeLocations = excludeList;
            }

            projectMan.updateProject(pro);
            changed = false;
            lsvProjectList.Sort();
            if (pro.ModrecorderCreated)
                pro.ModRecorder.reload(pro);
            if (wasMonitoring)
                pro.startMonitoring();
            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// restores the files to prevoius state
        /// </summary>
        /// <param name="pro"></param>
        /// <param name="itemIndex"></param>
        private void restore(Project pro, int itemIndex)
        {
            if (lsvChanges.InvokeRequired)
            {
                lsvChanges.BeginInvoke(new MethodInvoker(() => restore(pro, itemIndex)));
            }
            else
            {
                selectProject(selProject);
                changeLogEntry lastEntry = (changeLogEntry)lsvChanges.Items[itemIndex].Tag;
                Thread restoreThread = new Thread(delegate()
                {
                    updateing++;
                    bool monitoringState = pro.isMonitoring;
                    if (monitoringState)
                        pro.stopMonitoring();
                    pro.ModRecorder.updateChangeList -= new EventHandler(ModRecorder_updateChangeList);

                    changeLogEntry lastRemoved = pro.ModRecorder.revertsChange();
                    while (lastRemoved != null && !lastRemoved.Equals(lastEntry))
                    {
                        lastRemoved = pro.ModRecorder.revertsChange();
                    }
                    ModRecorder_updateChangeList(pro.ModRecorder, EventArgs.Empty);
                    pro.ModRecorder.updateChangeList += new EventHandler(ModRecorder_updateChangeList);
                    if (monitoringState)
                        pro.startMonitoring();
                    updateing--;
                });
                restoreThread.Start();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// loads the projects from the database
        /// </summary>
        public void loadProjects()
        {
            try
            {
                if (db == null)
                {
                    db = new sqlite("lvcontrol.db");
                    db.execute("CREATE TABLE IF NOT EXISTS projects (name, description, location, note, time DEFAULT (datetime('now')),autoMonitor)");
                    db.execute("CREATE TABLE IF NOT EXISTS excludeLocations (path, projectID)");
                }

                projects = new List<Project>();

                List<object[]> projectRaw = db.selectAll("projects", true);

                foreach (object[] cells in projectRaw)
                {
                    if (cells.Length >= 6)
                    {
                        try
                        {
                            long key = Convert.ToInt32(cells[0]);
                            string name = Convert.ToString(cells[1]);
                            string description = Convert.ToString(cells[2]);
                            string location = Convert.ToString(cells[3]);
                            string note = Convert.ToString(cells[4]);
                            bool auto = Convert.ToBoolean(cells[6]);
                            DateTime time = Convert.ToDateTime(Convert.ToString(cells[5]));
                            SqliteParameters parm = new SqliteParameters();
                            parm.add("@proID", key);
                            Project pro = new Project(key, name, description, location, note, time, auto);

                            db.query(@"SELECT path FROM excludeLocations WHERE projectID=@proID", parm);

                            List<object[]> tableData = new List<object[]>();

                            object[] values = db.readNext();
                            while (values != null)
                            {
                                pro.loadExcludeLocation(Convert.ToString(values[0]));
                                values = db.readNext();
                            }

                            projects.Add(pro);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Failed to load a Project will continue loading", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to load Project unable to continue. Try restarting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// creates a new blank project
 /// </summary>
 /// <returns></returns>
 public Project createProject()
 {
     Project newProject = new Project();
     projects.Add(newProject);
     return newProject;
 }
Exemplo n.º 6
0
 /// <summary>
 /// saves the changes of a project to the database
 /// </summary>
 /// <param name="pro"></param>
 public void updateProject(Project pro)
 {
     SqliteParameters parm = new SqliteParameters();
     parm.add("@newName", pro.Name);
     parm.add("@newDesc", pro.Description);
     parm.add("@newLocation", pro.Location);
     parm.add("@newNote", pro.Note);
     parm.add("@newTime", String.Format("{0:yyyy-MM-dd HH:mm:ss}", pro.Time));
     parm.add("@newAuto", pro.AutoMonitor);
     parm.add("@ID", pro.Key);
     if (pro.NewEntry)
     {
         db.execute("INSERT INTO projects (name, description, location, note, time, autoMonitor ) VALUES (@newName,@newDesc,@newLocation,@newNote,@newTime,@newAuto)", parm);
         pro.Key = db.lastID();
         pro.NewEntry = false;
     }
     else
     {
         db.execute("UPDATE projects SET name = @newName, description = @newDesc, location = @newLocation, time = @newTime, autoMonitor= @newAuto WHERE rowid=@ID", parm);
     }
     if (pro.ExcludeLocationsChanged)
     {
         parm = new SqliteParameters();
         parm.add("@proID", pro.Key);
         parm.add("@newpath", "");
         db.execute(@"DELETE FROM excludeLocations WHERE projectID=@proID", parm);
         if (pro.ExcludeLocations != null)
         {
             foreach (string path in pro.ExcludeLocations)
             {
                 parm.edit("@newpath", path);
                 db.execute("INSERT INTO excludeLocations (path, projectID ) VALUES (@newpath,@proID)", parm);
             }
         }
     }
     pro.ModRecorder.reload(pro);
 }
Exemplo n.º 7
0
 /// <summary>
 /// saves teh not of an applcation to the database
 /// </summary>
 /// <param name="pro"></param>
 public void updateNote(Project pro)
 {
     SqliteParameters parm = new SqliteParameters();
     parm.add("@newNote", pro.Note);
     parm.add("@ID", pro.Key);
     db.execute("UPDATE projects SET note = @newNote WHERE rowid=@ID", parm);
 }
Exemplo n.º 8
0
        /// <summary>
        /// removes the project from the local list and from the database
        /// </summary>
        /// <param name="pro"></param>
        public void removeProject(Project pro)
        {
            if (!pro.NewEntry)
            {
                SqliteParameters parm = new SqliteParameters();
                parm.add("@ID", pro.Key);
                db.execute("DELETE FROM projects WHERE rowid=@ID", parm);

            }
            projects.Remove(pro);
        }
Exemplo n.º 9
0
 /// <summary>
 /// set up file monitor with the location and project
 /// </summary>
 /// <param name="pro"></param>
 public FileMonitor(Project pro)
 {
     this.Location = pro.Location;
     this.project = pro;
 }