public void Setup() { var fileSystem = FileSystem.Simulated(); _charFile = fileSystem.Directory(@"C:\The\Folder").File("CharName.ars"); _charFile.Overwrite(FakeCharData); _testSubject = new AppModel(fileSystem); }
public NewFileSignal(RelPath fileName, FsFile<RelPath> descriptor, IList<PieceHash> hashes) { this.fileName = fileName; this.descriptor = descriptor; this.hashes = hashes; }
public NewFileBroadcast(RelPath fileName, FsFile<RelPath> descriptor, string seedUser, IList<PieceHash> hashes) { this.fileName = fileName; this.descriptor = descriptor; this.seedUser = seedUser; this.hashes = hashes; }
public void ChangeExtension() { // Setup var file = new FsFile(@"x:\directory\File.txt"); // Execute var result = file.ChangeExtension("jpg"); Assert.AreEqual("File.jpg", result.Name); Assert.AreEqual(@"x:\directory\File.jpg", result.Path); }
public void GetDirectory() { // Setup var file = new FsFile(@"x:\directory\File.txt"); // Execute var result = file.Directory; // Assert Assert.AreEqual("directory", result.Name); Assert.AreEqual(@"x:\directory", result.Path); }
private IEnumerable <OutputFile> ToOutputFile(FsFile <Start> fsFile) { var ast = (Start)fsFile.Ast; if (ast.IsAllPropertiesEvaluated && ast.Top is TopWithNode) { var withNode = (TopWithNode)ast.Top; if (withNode.IsXamlEvaluated) { yield return(new OutputFile(fsFile.FullName, withNode.Xaml.Build())); } } }
/// <summary> /// Wywolywana gdy lokalnie zostanie wykryty nowy plik /// </summary> /// <param name = "descr"></param> /// <param name = "path"></param> public void NewFileVersion(FsFile<RelPath> descr, string path) { try { IList<PieceHash> hashes = _dataManager.HashAll(path); NewFileSignal mess = new NewFileSignal(descr.Path, descr, hashes); } catch (Exception e) { Console.WriteLine(e); } }
public Xb2Fs(string directory) { string baseDir = Path.Combine(directory, "base"); string dlcDir = Path.Combine(directory, "dlc"); if (!Directory.Exists(baseDir)) { throw new DirectoryNotFoundException($"Could not find {baseDir}"); } var dirs = new List <string>(); if (Directory.Exists(dlcDir)) { string[] dlcDirs = Directory.GetDirectories(dlcDir); dirs.AddRange(dlcDirs); } dirs.Add(baseDir); for (int i = 0; i < dirs.Count; i++) { foreach (string file in Directory.GetFiles(dirs[i], "*", SearchOption.AllDirectories)) { string path = Helpers.GetRelativePath(file, dirs[i]); path = path.Replace('\\', '/'); if (path[0] != '/') { path = '/' + path; } if (path == "key.bin") { continue; } Files[path] = new FsFile(file, i); //Files.Add(path, new FsFile(file, i)); } } string arh = Path.Combine(baseDir, "bf2.arh"); string ard = Path.Combine(baseDir, "bf2.ard"); if (File.Exists(arh) && File.Exists(ard)) { Archive = new FileArchive(arh, ard); foreach (FileInfo file in Archive.FileInfo.Where(x => x.Filename != null)) //Todo: Investigate { Files.Add(file.Filename, new FsFile(file.Filename, -1)); } } }
public override bool TryGetFile(string path, out FileFile value) { value = null; string physicalPath = ToPhysicalPath(path); if (!File.Exists(physicalPath)) { return(false); } string rootedName = ToRootedName(path); string name = ToName(path); value = new FsFile(physicalPath, rootedName, name); return(true); }
public void Copy(FsFile source, FsFile dest) { _size = source.Size; var cancel = 0; var success = CopyFileEx( source, dest, CopyProgressRoutineImpl, IntPtr.Zero, ref cancel, CopyFileFlags.COPY_FILE_RESTARTABLE); if (!success) { throw new Exception($"File '{source}' could not be copied to '{dest}'"); } if (_transferred != _size) { _progress(_size - _transferred, _size); } }
public FsFileInfo UpdateFile(string serverName, string destfileName, long fileSize, string relateId, string fileCode, string version, string src) { //记录日志 logFO.AddLog(destfileName, "UpdateFile", serverName); int fileID = FileHelper.GetFileId(destfileName); FsFile file = entities.FsFile.Where(c => c.Id == fileID).SingleOrDefault(); file.IsDeleted = "0"; file.FileSize = fileSize; file.RelateId = relateId; file.Code = fileCode; file.Version = version; file.Src = src; var fileServer = entities.FsServer.Where(c => c.ServerName == serverName).SingleOrDefault(); file.UploadServerName = fileServer.ServerName; file.FileServerNames = fileServer.ServerName; file.OnMaster = fileServer.IsMaster; file.Status = ""; entities.SaveChanges(); var fsRoot = GetAvailableRootFolder(serverName, src, file.ExtName); return(new FsFileInfo() { FileName = file.Name, FileSize = (long)file.FileSize, FileFullPath = FileHelper.GetFileFullPath(fsRoot.RootFolderPath, file.Name, file.Guid, fsRoot.AllowEncrypt == "1"), SrcFileFullPath = "", SrcFileServiceUrl = "" }); }
public CharacterModel(FsFile charFile) { _File = charFile; }
public void ConstructFsFileWithNullPath() { // Execute var file = new FsFile(a_filePath: null); }
/// <summary> /// RelPath must be relative to rootDirectory /// </summary> /// <param name="descriptor"></param> public void AddFile(FsFile<RelPath> descriptor) { DirNode parent = GetParentDir(descriptor.Path); parent.AddFile(descriptor.NewAsName()); }
/// <summary> /// /// </summary> /// <param name="descriptor"></param> /// <returns>Created DirNode if parameter is a directory, null otherwise.</returns> // public DirNode Add(FsObject<RelPath> descriptor) // { // var name = descriptor.Name; // if (descriptor is FsFile<RelPath>) // { // FsFile<RelPath> file = (FsFile<RelPath>)descriptor; // _files.Add(name, new FsFile<Name>(name, file.Size, file.LastWrite)); // return null; // } // else // { // var dir = new DirNode(name, this); // _directories.Add(name, dir); // return dir; // } // } public void AddFile(FsFile<Name> descriptor) { _files.Add(descriptor.Path, descriptor); }
public bool TryGetFile(RelPath path, out FsFile<RelPath> file) { try { file = GetFile(path); return true; } catch (KeyNotFoundException ) { file = default(FsFile<RelPath>); return false; } }
public void ChangeFile(FsFile<RelPath> newFile) { DirNode node = GetNode(newFile.Path.GetAncestorFolders()); if(!node.Remove(newFile.Path.FileName())) { throw new KeyNotFoundException(); } node.AddFile(newFile.NewAsName()); }
public FsFileInfo AddFile(string serverName, string destfileName, long fileSize, string relateId, string fileCode, string version, string src) { //文件名中不能包含半角逗号 destfileName = destfileName.Replace(',', ','); FsFile file = new FsFile(); file.Name = ""; file.ExtName = ""; if (destfileName.Contains('.')) { file.ExtName = destfileName.Split('.').Last(); } file.IsDeleted = "0"; file.FileSize = fileSize; file.RelateId = relateId; file.Code = fileCode; file.Version = version; file.Src = src; file.CreateTime = DateTime.Now; file.Guid = Guid.NewGuid().ToString(); var fileServer = entities.FsServer.Where(c => c.ServerName == serverName).SingleOrDefault(); file.UploadServerName = fileServer.ServerName; file.FileServerNames = fileServer.ServerName; file.OnMaster = fileServer.IsMaster; file.Status = ""; if (Config.Constant.IsOracleDb) { var sqlHelper = Config.SQLHelper.CreateSqlHelper("FileStore"); var idvalue = sqlHelper.ExecuteScalar("select FSFILE_SEQUENCE.nextval from dual").ToString(); file.Name = idvalue + "_" + destfileName; var sql = "INSERT INTO FSFILE( ID ,\"NAME\",EXTNAME,FILESIZE,RELATEID,CODE,VERSION,CREATETIME,ISDELETED,DELETETIME,DELETEREASON,SRC,ONMASTER,UPLOADSERVERNAME,FILESERVERNAMES,GUID,STATUS,ERRORCOUNT,ERRORTIME) VALUES ({18},'{0}','{1}','{2}','{3}','{4}','{5}',to_date('{6}','yyyy/MM/dd hh24:mi:ss'),'{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}')"; sql = string.Format(sql, file.Name, file.ExtName, file.FileSize, file.RelateId, file.Code, file.Version, file.CreateTime, file.IsDeleted, file.DeleteTime, file.DeleteReason, file.Src, file.OnMaster, file.UploadServerName, file.FileServerNames, file.Guid, file.Status, file.ErrorCount, file.ErrorTime, idvalue.ToString()); sqlHelper.ExecuteNonQuery(sql); } else { entities.FsFile.Add(file); entities.SaveChanges(); file.Name = string.Format("{0}_{1}", file.Id, destfileName); } entities.SaveChanges(); var fsRoot = GetAvailableRootFolder(serverName, src, file.ExtName); string fileFullPath = FileHelper.GetFileFullPath(fsRoot.RootFolderPath, file.Name, file.Guid, fsRoot.AllowEncrypt == "1"); //记录日志 logFO.AddLog(file.Name, "AddFile", serverName); return(new FsFileInfo() { FileName = file.Name, FileSize = (long)file.FileSize, FileFullPath = fileFullPath, SrcFileFullPath = "", SrcFileServiceUrl = "" }); }
private void FileModified(FsFile<RelPath> oldFileProps, FsFile<RelPath> newFileProps) { Console.WriteLine("File Modified: " + newFileProps.Path); FileIndex.Remove(oldFileProps); FileIndex.Add(newFileProps); }
public void ConstructFsFileWithBadPath() { // Execute var file = new FsFile("???"); }
public void SelectCharacter(FsFile charFile) { Character = new CharacterModel(charFile); }
private FsItem GetItem(ResponseBodyStream data, FsFolder folder) { FsItem item; TreeId treeId; int head = data.ReadIntSpl(); if ((head & 4096) != 0) { byte[] nodeId = data.ReadNBytes(16); } string name = data.ReadNBytesAsString(data.ReadShort()); data.ReadULong(); // dunno ulong?GetFolderSize() => (Options & Option.FolderSize) != 0 ? (ulong?)data.ReadULong() : null; void ProcessDelete() { if ((Options & Option.Delete) != 0) { data.ReadPu32(); // dunno data.ReadPu32(); // dunno } } int opresult = head & 3; switch (opresult) { case 0: // folder? treeId = data.ReadTreeId(); data.ReadULong(); // dunno data.ReadULong(); // dunno ProcessDelete(); item = new FsFolder(WebDavPath.Combine(folder.FullPath, name), treeId, CloudFolderType.MountPoint, folder, GetFolderSize()); break; case 1: var modifDate = data.ReadDate(); ulong size = data.ReadULong(); byte[] sha1 = data.ReadNBytes(20); //item = new FsFile(WebDavPath.Combine(folder.FullPath == string.Empty ? _fullPath : folder.FullPath, name), modifDate, sha1, size); item = new FsFile(WebDavPath.Combine(folder.FullPath, name), modifDate, sha1, size); break; case 2: data.ReadULong(); // dunno ProcessDelete(); item = new FsFolder(WebDavPath.Combine(folder.FullPath, name), null, CloudFolderType.Generic, folder, GetFolderSize()); break; case 3: data.ReadULong(); // dunno treeId = data.ReadTreeId(); ProcessDelete(); item = new FsFolder(WebDavPath.Combine(folder.FullPath, name), treeId, CloudFolderType.Shared, folder, GetFolderSize()); break; default: throw new Exception("unknown opresult " + opresult); } return(item); }
protected override void FinishSetup() { _testFile = _runRootFolder.File("CreatedByTest.txt"); }