Пример #1
0
        public ActionResult CopyFile(CopyModel model)
        {
            if (ModelState.IsValid)
            {
                AbstractFile file = SessionVariables.GetFileLoader().LoadAbstractFile(model.File.GetFSInfo());
                System.Diagnostics.Debug.WriteLine("copy file, model is:");
                System.Diagnostics.Debug.WriteLine(file.FullName);
                System.Diagnostics.Debug.WriteLine(model.NewPath);
                SqliteDatabase db = new SqliteDatabase(User.Identity.Name);

                string pattern = ".*.Users.";
                System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);

                if (file.IsFile())
                {
                    if (file is AudioFile)
                    {
                        string path = rgx.Replace(model.NewPath, "");

                        db.ExecuteNonQuery("insert into audio_files(path, name) values ('" + String.Format("{0}\\{1}", path, file.Name).Replace("'", "''") + "', '" + file.Name + "')");
                    }
                    else if (file is VideoFile)
                    {
                        string path = rgx.Replace(model.NewPath, "");

                        db.ExecuteNonQuery("insert into video_files(path, name) values ('" + String.Format("{0}\\{1}", path, file.Name).Replace("'", "''") + "', '" + file.Name + "')");
                    }
                }
                else if (file.IsFolder())
                {
                    string oldPath = rgx.Replace(file.FullName, "");
                    string newPath = rgx.Replace(model.NewPath, "");

                    string patt = User.Identity.Name + ".";
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(patt);

                    DataTable audio_files = db.GetDataTable("select * from audio_files where path like '" + oldPath + "%'");
                    foreach (DataRow row in audio_files.Rows)
                    {
                        string path = (string)row["path"];
                        string reducedPath = regex.Replace(path, "");

                        string name = (string)row["name"];

                        db.ExecuteNonQuery("insert into audio_files(path, name) values ('" + String.Format("{0}\\{1}", newPath, reducedPath).Replace("'", "''") + "', '" + name + "')");
                    }

                    DataTable video_files = db.GetDataTable("select * from video_files where path like '" + oldPath + "%'");
                    foreach (DataRow row in video_files.Rows)
                    {
                        string path = (string)row["path"];
                        string reducedPath = regex.Replace(path, "");

                        string name = (string)row["name"];

                        db.ExecuteNonQuery("insert into video_files(path, name) values ('" + String.Format("{0}\\{1}", newPath, reducedPath).Replace("'", "''") + "', '" + name + "')");
                    }
                }

                db.Dispose();

                file.Copy(model.NewPath);
            }
            return RedirectToAction("Browse");
        }
Пример #2
0
        public ActionResult RenameFile(RenameModel model)
        {
            if (ModelState.IsValid)
            {
                FileLoader fl = SessionVariables.GetFileLoader();
                AbstractFile file = fl.LoadAbstractFile(model.File.GetFSInfo());
                System.Diagnostics.Debug.WriteLine("rename file, model is:");
                System.Diagnostics.Debug.WriteLine(file.FullName);
                System.Diagnostics.Debug.WriteLine(model.NewName);

                SqliteDatabase db = new SqliteDatabase(User.Identity.Name);

                string pattern = ".*.Users.";
                System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);

                string oldPath = rgx.Replace(file.FullName, "");

                file.Rename(model.NewName);

                if (file is AudioFile)
                {
                    string newPath = rgx.Replace(file.FullName, "");

                    db.ExecuteNonQuery("update audio_files set path = '" + newPath.Replace("'", "''") + "', name = '" + file.Name + "' where path like '" + oldPath + "'");
                }
                else if (file is VideoFile)
                {
                    string newPath = rgx.Replace(file.FullName, "");

                    db.ExecuteNonQuery("update video_files set path = '" + newPath.Replace("'", "''") + "', name = '" + file.Name + "' where path like '" + oldPath + "'");
                }

                db.Dispose();

                fl.RefreshWorkingFolder(SessionVariables.GetWorkingFolder());
            }
            return RedirectToAction("Browse");
        }
Пример #3
0
        public ActionResult UploadFinished()
        {
            List<AbstractFile> oldFiles = new List<AbstractFile>(SessionVariables.GetWorkingFolder().GetFiles());

            SessionVariables.GetFileLoader().RefreshWorkingFolder(SessionVariables.GetWorkingFolder());

            List<AbstractFile> newFiles = SessionVariables.GetWorkingFolder().GetFiles();

            SqliteDatabase db = new SqliteDatabase(User.Identity.Name);

            String workingDir = Calamity.MyHelpers.SessionVariables.GetWorkingFolder().FullName;
            // C:\\Users\\Patrik\\Desktop\\WT\\Calamity\\Calamity\\Users\\

            string pattern = ".*.Users.";
            System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);

            List<AbstractFile> result = newFiles.Except(oldFiles).ToList();
            foreach (AbstractFile file in result)
            {
                if (file.IsFile())
                {
                    if (file is AudioFile)
                    {
                        string path = rgx.Replace(file.FullName, "");

                        db.ExecuteNonQuery("insert into audio_files(path, name) values ('" + path.Replace("'", "''") + "', '" + file.Name + "')");
                    }
                    else if (file is VideoFile)
                    {
                        string path = rgx.Replace(file.FullName, "");

                        db.ExecuteNonQuery("insert into video_files(path, name) values ('" + path.Replace("'", "''") + "', '" + file.Name + "')");
                    }
                }
            }

            db.Dispose();

            return RedirectToAction("Browse", "Browser");
        }
Пример #4
0
        public ActionResult DeleteFile(String name)
        {
            FileLoader fl = SessionVariables.GetFileLoader();
            AbstractFile file = fl.LoadAbstractFile(name.GetFSInfo());

            SqliteDatabase db = new SqliteDatabase(User.Identity.Name);

            string pattern = ".*.Users.";
            System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);

            if (file.IsFile())
            {
                if (file is AudioFile)
                {
                    string path = rgx.Replace(file.FullName, "");

                    db.ExecuteNonQuery("delete from playlists where audio_id = (select audio_id from audio_files where path like '" + path + "%')");
                    db.ExecuteNonQuery("delete from audio_files where path like '" + path + "'");
                }
                else if (file is VideoFile)
                {
                    string path = rgx.Replace(file.FullName, "");

                    db.ExecuteNonQuery("delete from video_files where path like '" + path + "'");
                }
            }
            else if (file.IsFolder())
            {
                string path = rgx.Replace(file.FullName, "");

                db.ExecuteNonQuery("delete from playlists where audio_id = (select audio_id from audio_files where path like '" + path + "%')");

                db.ExecuteNonQuery("delete from audio_files where path like '" + path + "%'");
                db.ExecuteNonQuery("delete from video_files where path like '" + path + "%'");
            }

            db.Dispose();

            file.Delete();
            fl.RefreshWorkingFolder(SessionVariables.GetWorkingFolder());
            return RedirectToAction("Browse");
        }