public static void SharingFile_Delete(String[] copyRefs) { lock ( conn ) { foreach (String copyRef in copyRefs) { if (PreKeyring.GetRowsCountOfCopyRef(copyRef) == 0) { continue; } else { String sql = string.Format(SQLStatement.SharingFile_Delete, copyRef); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); } } } } }
public static void SharingFile_Delete(String copyRef) { lock ( conn ) { if (PreKeyring.GetRowsCountOfCopyRef(copyRef) == 0) { return; } else { String sql = string.Format(SQLStatement.SharingFile_Delete, copyRef); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) { throw new SecuruStikException("Unexpected SQL database outcome"); } } } } }
public static void SharingFile_Update(SharingInfo sf) { if (PreKeyring.SharingFile_Query(sf.CopyRef) == null) { SharingFile_Insert(sf); } else { lock (PreKeyring.conn) { String sql = string.Format(SQLStatement.SharingFile_Update, sf.CopyRef, sf.FileName, sf.ID_From, sf.CKEY_E, sf.CKEY_F, sf.CKEY_U, sf.CKEY_W); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) { throw new DBException(); } } } } }
public static void FileInfo_Delete(String[] filePaths) { lock ( conn ) { if (conn.State == ConnectionState.Closed) { conn.Open(); } SqliteCommand cmd = new SqliteCommand(); cmd.Connection = PreKeyring.conn; foreach (String filePath in filePaths) { try { String fileFullPath = Path.GetFullPath(filePath); if (PreKeyring.GetRowsCountOfFilePath(fileFullPath) == 0) { continue; } else { String sql = string.Format(SQLStatement.FileInfo_Delete, fileFullPath); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } } catch (System.Exception) { log.ErrorFormat("FileInfo delete {0}", filePath); continue; } } conn.Close(); } }
public static Boolean FileInfo_Delete(String filePath) { lock ( conn ) { try { String fileFullPath = Path.GetFullPath(filePath); if (PreKeyring.GetRowsCountOfFilePath(fileFullPath) == 0) { return(false); } else { String sql = string.Format(SQLStatement.FileInfo_Delete, fileFullPath); conn.Open(); using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) { return(false); } } } } catch (Exception) { log.ErrorFormat("FileInfo delete {0}", filePath); return(false); } } return(true); }
public static void FILEINFO_TEST() { PreKeyring.FileInfo_Update(new FileMetaData { FileName = "HJY", FilePath = "SCAU", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); FileMetaData fi = PreKeyring.FileInfo_Query("SCAU"); Console.WriteLine( fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); PreKeyring.FileInfo_Update(new FileMetaData { FileName = "HJY2", FilePath = "SCAU2", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); PreKeyring.FileInfo_Update(new FileMetaData { FileName = "HJY2", FilePath = "SCAU3", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); PreKeyring.FileInfo_Update(new FileMetaData { FileName = "DLC", FilePath = "SCAU", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); fi = PreKeyring.FileInfo_Query("HHHHH"); Console.WriteLine( (fi == null) ? "The File HHHHH is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); //PreKeyring.FileInfo_Delete( new String[]{"SCAU2","SCAU3"} ); fi = PreKeyring.FileInfo_Query("SCAU2"); Console.WriteLine( (fi == null) ? "The File SCAU2 is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); fi = PreKeyring.FileInfo_Query("SCAU3"); Console.WriteLine( (fi == null) ? "The File SCAU3 is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); PreKeyring.Close(); }
static void Main(string[] args) { FileMetaData fi = PreKeyring.FileInfo_Query(@"C:\Users\637\Documents\SecuruStik\Home\RestartExplorer.bat"); Console.WriteLine( (fi == null) ? "The File HHHHH is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); Console.ReadLine(); }
public static void SharingFile_TEST() { PreKeyring.SharingFile_Update( new SharingInfo { CopyRef = "ref1", FileName = "file", ID_From = "Hjnubys", CKEY_E = "testE", CKEY_F = "testF", CKEY_U = "testU", CKEY_W = "testW" }); PreKeyring.SharingFile_Update(new SharingInfo { CopyRef = "ref2", FileName = "file2", ID_From = "Hjnubys", CKEY_E = "testE", CKEY_F = "testF", CKEY_U = "testU", CKEY_W = "testW" }); PreKeyring.SharingFile_Update(new SharingInfo { CopyRef = "ref3", FileName = "file2", ID_From = "Hjnubys", CKEY_E = "testE", CKEY_F = "testF", CKEY_U = "testU", CKEY_W = "testW" }); SharingInfo sf = PreKeyring.SharingFile_Query("ref1"); Console.WriteLine( (sf == null) ? "The SharingFileInfo is not exist" : "Find the file info of the copyref with ref"); PreKeyring.SharingFile_Delete(new String[] { "ref1", "ref3" }); List <SharingInfo> sharingfileList = PreKeyring.GetSharingFileList(); foreach (SharingInfo f in sharingfileList) { Console.WriteLine(f.CopyRef + " " + f.FileName + " " + f.ID_From + " " + f.CKEY_E + " " + f.CKEY_F + " " + f.CKEY_U + " " + f.CKEY_W + " "); } }
public static Boolean FileInfo_Update(FileMetaData fi) { lock ( conn ) { try { if (fi.Key == null) { return(false); } fi.FilePath = Path.GetFullPath(fi.FilePath); fi.Key = Base64String.StringToBase64String(fi.Key); if (PreKeyring.GetRowsCountOfFilePath(fi.FilePath) == 0) { FileInfo_Insert(fi); } else { String sql = string.Format(SQLStatement.FileInfo_Update, fi.FileName, fi.FilePath, fi.Key, fi.PlainTextHash, fi.CryptTextHash); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) { return(false); } } } } catch (System.Exception) { log.ErrorFormat("Update {0}", fi.FilePath); } } return(true); }