void s_OnFileXferProgress(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer) { Console.WriteLine("File progress ({0}): {1}/{2}; localpath: {3}", fileXfer.get_Property(AccFileXferProp.AccFileXferProp_Name), fileXfer.get_Property(AccFileXferProp.AccFileXferProp_BytesXferred), fileXfer.get_Property(AccFileXferProp.AccFileXferProp_Bytes), fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath)); }
void s_OnFileXferCollision(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer) { Console.WriteLine("file already existed - replacing.."); fileXferSession.ResolveCollision(AccFileXferSessionCollisionAction.AccFileXferSessionCollisionAction_ReplaceAll, fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath).ToString()); }
void s_OnFileXferComplete(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer, AccResult hr) { try { string user = fileXferSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(); Console.WriteLine("File transfer complete! (from user: {0})", user); long size = Int64.Parse(fileXferSession.get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_TotalBytes).ToString()); if (!uploadSize.ContainsKey(user)) { uploadSize.Add(user, size); } else { uploadSize[user] += size; } // move the file to where we want it string localPath = fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath).ToString(); string fileName = user + "\\" + localPath.Substring(DEFAULT_DOWNLOAD_PATH.Length); // we need to create all the necessary directories string[] parts = fileName.Split('\\'); string dir = ""; for (int i = 0; i < parts.Length - 1; i++) { string currentDir = BASE_PATH + dir + parts[i]; if (!Directory.Exists(currentDir)) { Directory.CreateDirectory(currentDir); } dir += parts[i] + "\\"; } // check if it already existed, if so delete it if (File.Exists(BASE_PATH + fileName)) { File.Delete(BASE_PATH + fileName); } File.Move(localPath, BASE_PATH + fileName); // add it to uploads db // if it already existed remove it beforehand if (uploads.ContainsKey(fileName)) { uploads.Remove(fileName); } uploads.Add(fileName, new Upload(fileName, DateTime.Now)); // now remove the old directory, if any if (parts.Length > 2 && Directory.Exists(DEFAULT_DOWNLOAD_PATH + parts[1])) { Directory.Delete(DEFAULT_DOWNLOAD_PATH + parts[1], true); } } catch (Exception e) { Console.WriteLine("exception occurred when completing transfer: " + e.Message + e.StackTrace); } }
void s_OnNewFileXfer(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer) { try { Console.WriteLine("Got a new file Xfer!"); } catch (Exception e) { Console.WriteLine("exception encountered when trying to start file xfer: {0}", e.Message + e.StackTrace); } }