/// <summary> /// Update or add an entry for a file in the shared files /// database. /// </summary> /// <param name="info">FileInfo for the file to process.</param> private void ProcessFile(FileInfo info) { FilesDataSet.SharesDataTable shares = files.Shares; Action action; string hash; // See if this file is already in the database. FilesDataSet.SharesRow row = shares.FindByFullName(info.FullName); if (row != null) { // The file was found, so keep this row. row.Keep = true; // Update the hash if this file was modified since we // last saw it. if (row.LastModified < info.LastWriteTime) { hash = ComputeHashForFile(info.FullName); // Delete the row if this file is now a duplicate. if (shares.Select("Hash = '" + hash + "'").Length > 0) { row.Delete(); action = Action.DuplicateDeleted; } else { // File modified, update the hash. row.Hash = hash; action = Action.HashUpdated; } } else { // This file was already in the database and // has not been modified. return; } } else { hash = ComputeHashForFile(info.FullName); // Don't add this file if this is a duplicate. if (shares.Select("Hash = '" + hash + "'").Length > 0) { action = Action.DuplicateIgnored; } else { // This is a new file, add it. shares.AddSharesRow(info.FullName, hash, info.LastWriteTime, info.Length, true); action = Action.Added; } } OnFileUpdated(new FileUpdatedEventArgs(info, action)); }
public void StartServer(FilesDataSet.SharesDataTable shares) { this.shares = shares; this.port = (int)Sideris.Properties.Settings.Default.Port; ThreadPool.QueueUserWorkItem(new WaitCallback(this.Start)); }
private void StartScan(object state) { string sharedFolder; bool subfolders; lock (Properties.Settings.Default) { sharedFolder = Properties.Settings.Default.SharedFolder; subfolders = Properties.Settings.Default.IncludeSubfolders; } // If the share directory does not exist, silently get out. if (!Directory.Exists(sharedFolder)) { return; } FilesDataSet.SharesDataTable shares = files.Shares; // Set the Keep column of all files to false. // Whenever we encounter a file, the Keep column will // be set to true. This way, deleted files will be removed // from the database. foreach (FilesDataSet.SharesRow row in shares.Rows) { row.Keep = false; } ScanFolder(new DirectoryInfo(sharedFolder), subfolders); // Delete rows for all files that do not exist anymore, // or are not shared anymore. DataRow[] rows = shares.Select("Keep = false"); foreach (DataRow row in rows) { row.Delete(); } shares.AcceptChanges(); OnScanComplete(new EventArgs()); }
public SharesView(FilesDataSet files) { InitializeComponent(); this.shares = files.Shares; }