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"); }
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"); }
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"); }
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"); }
public ActionResult Register(RegisterModel model) { System.Diagnostics.Debug.WriteLine("starting registration"); if (ModelState.IsValid) { String user = String.Format("C:\\Users\\Patrik\\Desktop\\WT\\Calamity\\Calamity\\Users\\{0}", model.UserName); String pathToDatabase = String.Format(Calamity.Properties.Settings.Default.pathToDatabase + "{0}", model.UserName); System.Diagnostics.Debug.WriteLine("modelstate is valid"); // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); System.IO.Directory.CreateDirectory(user); System.IO.Directory.CreateDirectory(pathToDatabase); SQLiteConnection.CreateFile(pathToDatabase + "\\playlist.sqlite"); SqliteDatabase db = new SqliteDatabase(model.UserName); db.createTables(); db.Dispose(); System.Diagnostics.Debug.WriteLine("hopefully created directory for user: {0}", User.Identity.Name); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } System.Diagnostics.Debug.WriteLine("something f****d up"); // If we got this far, something failed, redisplay form return View(model); }