public override YukaGraphic Read(string name, FileSystem fs, FileList files) { // TODO handle pure alpha files if (name.EndsWith(Gnp.AlphaExtension) && fs.FileExists(name.Substring(0, name.Length - Gnp.AlphaExtension.Length))) { return(null); } // load color data byte[] colorData; using (var r = fs.OpenFile(name).NewReader()) { colorData = r.ReadToEnd(); } files?.Add(name, Gnp); Debug.Assert(colorData.Length >= Gnp.Signature.Length); // change file header for (int i = 0; i < Png.Signature.Length; i++) { colorData[i] = Png.Signature[i]; } // check if alpha channel file exists string alphaFileName = name.WithExtension(Gnp.AlphaExtension); byte[] alphaData = null; if (fs.FileExists(alphaFileName)) { using (var r = fs.OpenFile(alphaFileName).NewReader()) { alphaData = r.ReadToEnd(); } files?.Add(alphaFileName, Gnp); } // load animation file if there is one string aniFileName = name.WithExtension(Ani.Extension); string frmFileName = name.WithExtension(Frm.Extension); var animation = fs.FileExists(aniFileName) ? Decode <Animation>(aniFileName, fs, files) : fs.FileExists(frmFileName) ? Decode <Animation>(frmFileName, fs, files) : null; return(new YukaGraphic { ColorData = colorData, AlphaData = alphaData, Animation = animation }); }
private void Crawl() { //pick relevant files to display //if properly set if (this.selectedFilePath.Length > rootFileLength && this.selectedFilePath.Substring(this.selectedFilePath.Length - rootFileLength) == "database.xml") { List <string> result = new List <string>(); //crawl through "StreamingAssets/", get all file paths (caveat, does not return files in root folder) DirCrawl(this.selectedFilePath.Substring(0, this.selectedFilePath.Length - rootFileLength), result); /* operating assumption: root database.xml is list of DB.xml files to compile to RAM during game start * therefore, relevant default xmls are those included there, and relevant non-default xmls must be * added there. Same applies to eventModules.xml and terrains.xml. I'm going to assume alternativeDatabase * is for temporary EA compatibility and ignore it (to my peril). * * terrains points to filenames in "Terrain Sources/", eventModules contains actual paths to event files * (eg. "Modules/Death.xml") along with some XDEBUGs pulled from IDK where. database.xml has DATA nodes * with 'name' tags of files in "DataBase/", and PROTOTYPE nodes with "name" tags in "DataBase/(Prototype/)". * I'm going to assume we're only modding actual xmls, and ignore protos for now */ FileList.Clear(); foreach (string x in result) { //actually, dir list, but W/E FileList.Add(x.Remove(0, this.selectedFilePath.Length - rootFileLength)); //add paths truncated to root } } else { MessageBox.Show("Please select database.xml"); } }
private void _downFile(Uri uri) { var file = new FileUrl(uri); FileList.Add(file); file.DownFileAsync(); }
private async Task FileNameChanged(ChangeEventArgs e) { var value = e.Value?.ToString(); if (string.IsNullOrWhiteSpace(value)) { return; } var fileName = value.Substring(value.LastIndexOf('\\') + 1); var id = Guid.NewGuid().ToString(); var fileItem = await JSRuntime.InvokeAsync <UploadFileItem>(JSInteropConstants.getFileInfo, _file); fileItem.Ext = fileName.Substring(fileName.LastIndexOf('.')); if (BeforeUpload != null) { if (!BeforeUpload.Invoke(fileItem)) { return; } } fileItem.Progress = 0; fileItem.State = UploadState.Uploading; fileItem.Id = id; FileList.Add(fileItem); await InvokeAsync(StateHasChanged); await JSRuntime.InvokeVoidAsync(JSInteropConstants.uploadFile, _file, Headers, id, Action, Name, _currentInstance, "UploadChanged", "UploadSuccess", "UploadError"); await JSRuntime.InvokeVoidAsync(JSInteropConstants.clearFile, _file); }
public async Task PrepareFileList() { if (FileListLoaded) { return; } List <File> list = Model.GetFileList(CourseId); FileList.Clear(); foreach (File file in list) { FileList.Add(new FileVM(file)); } string id = CourseId; if (await Model.RefFileList(CourseId) == MainModel.UpdateResult.Success) { if (id == CourseId) { FileList.Clear(); foreach (File file in list) { FileList.Add(new FileVM(file)); } } } FileListLoaded = true; RaisePropertyChanged("FileList"); }
private void BrowseButton_Click(object sender, RoutedEventArgs e) { switch (((Button)sender).Content) { case "Browse": OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true; dialog.Filter = "Image Files |*.jpeg;*.png;*.jpg;"; if (dialog.ShowDialog() == true) { foreach (string file in dialog.FileNames) { DirList.Items.Add(file); FileList.Add(file); //Images.Add(new DImage() { // ImageName = Path.GetFileNameWithoutExtension(file), // ImageDir = Path.GetDirectoryName(file), // ImageHash = ImageHasher.CalculateDifferenceHash256(file) //}); } ((Button)sender).Content = "Scan"; } break; case "Scan": popup.PopupElement = new Scanning(); popup.ShowDialog(); break; default: break; } }
// overwrite default behavior so the file extension isn't deleted public override void Write(byte[] bytes, string baseName, FileSystem fs, FileList files) { using (var stream = fs.CreateFile(baseName)) { files?.Add(baseName, Format.Raw); Write(bytes, stream); } }
public override void Load(string filePath) { RootFolder = new LOFFolder(this); using (var fs = File.OpenRead(filePath)) using (var br = new BinaryReader(fs)) { fs.Seek(16, SeekOrigin.Begin); int fileCount = br.ReadInt32(); fs.Seek(4, SeekOrigin.Current); for (int i = 0; i < fileCount; i++) { fs.Seek(4 * 6, SeekOrigin.Current); // 6 ints readNullTerminated(br); // korean name, can ignore string fileName = readNullTerminated(br); fs.Seek(4 * 3, SeekOrigin.Current); // 3 ints int filePos = br.ReadInt32(); int fileLen = br.ReadInt32(); long tmpPos = fs.Position; fs.Seek(filePos, SeekOrigin.Begin); byte[] data = br.ReadBytes(fileLen); fs.Seek(tmpPos, SeekOrigin.Begin); var newFile = new LOFFile(RootFolder as LOFFolder, fileName, data); RootFolder.Files.Add(newFile); FileList.Add(newFile); } } }
/// <summary> /// 读取服务端更新日志记录 /// </summary> /// <param name="logUrl"></param> public void ReadUpdateLog(string logUrl) { try { System.Net.WebClient wc = new System.Net.WebClient(); wc.Encoding = Encoding.UTF8; string xmlStr = wc.DownloadString(logUrl); XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlStr.Trim()); XmlNode items = xml.SelectSingleNode("Items");//查找 if (items != null) { this.StartFile = items.Attributes["StartFile"].Value; this.Version = items.Attributes["Version"].Value; this.Description = items.Attributes["Description"].Value; this.UpdateTime = DateTime.Parse(items.Attributes["UpdateTime"].Value); this.VersionNumber = ParseVersionNumber(this.Version); JadeFile jf; FileList.Clear(); foreach (XmlNode item in items.ChildNodes) { jf = new JadeFile { FileName = item.Attributes["FileName"].Value, Url = item.Attributes["Url"].Value }; FileList.Add(jf); } } } catch (Exception ex) { Comm.AddLog("读取版本信息", ex); } }
public override void AddFile(string fileName, double fileSize, bool onlyRead, string system, bool hidden) { if (WriteDefense == true) { throw new Exception("The floppy has write defense"); } if (FileList.Count > 0) { foreach (File element in FileList) { if (element.FileName == fileName) { throw new Exception("This file is already in the file list"); } } } if (fileSize > this.FreeCapacity) { throw new Exception("There is not enough free capacity"); } else if (fileSize <= this.FreeCapacity) { File addfile = new File(fileName, fileSize, onlyRead, system, hidden); FileList.Add(addfile); return; } }
/// <summary> /// 递归获取指定类型文件,包含子文件夹 /// </summary>_FileList private void _Getallfiles(string path) { try { string[] dir = Directory.GetDirectories(path); //文件夹列表 DirectoryInfo fdir = new DirectoryInfo(path); //获取为文件夹的信息数组 FileInfo[] file = fdir.GetFiles(); FileCount += file.Length; DirCount += dir.Length; if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空 { foreach (FileInfo f in file) //添加当前目录所有文件到List { FileList.Add(f); } foreach (string d in dir) { _Getallfiles(d); //递归 } } } catch (Exception ex) { throw new IOException($"获取指定路径:{Path}失败,错误信息={ex.Message}"); } }
/// <summary> /// FileSystemTreeView_SelectedItemChanged /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FileSystemTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { FileAttributes attr = FileAttributes.Directory; try { attr = File.GetAttributes(((Item)fileSystemTreeView.SelectedItem).LongName); } catch (IOException) { return; } if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { return; } var item = FileList.SingleOrDefault(x => x.LongName == ((Item)fileSystemTreeView.SelectedItem).LongName); if (item == null) { FileList.Add(new FileName { SchortName = ((Item)fileSystemTreeView.SelectedItem).ShortName, LongName = ((Item)fileSystemTreeView.SelectedItem).LongName }); } else { SelectedFile = item; return; } SelectedFile = FileList[FileList.Count - 1]; }
public async Task <HttpResponseMessage <FileList> > PostFormData( ) { //TODO: store the original filename along with the file. if (!Request.Content.IsMimeMultipartContent( )) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var provider = new LocalCacheStreamProvider( ); try { await Request.Content.ReadAsMultipartAsync(provider); } catch (Exception ex) { throw new WebArgumentException(string.Format("Invalid file upload request. Request: {0}", Request), ex); } var idMap = new FileList( ); try { string expectedType = Request.RequestUri.ParseQueryString( )["type"]; foreach (var entry in provider.RemoteToLocalFileNameMap) { string remoteFileName = entry.Key; string localFileName = entry.Value; string token; if (!FileRepositoryHelper.CheckFileExtensionIsValid(remoteFileName, expectedType)) { throw new PlatformSecurityException("Disallowed file type."); } using (var source = new FileStream(localFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { token = FileRepositoryHelper.AddTemporaryFile(source); } idMap.Add(new FileListItem { FileName = remoteFileName, Hash = token }); } } finally { // clean up the local files foreach (var entry in provider.RemoteToLocalFileNameMap) { File.Delete(entry.Value); } } return(new HttpResponseMessage <FileList>(idMap)); }
public override void AddFile(string fileName, double fileSize, bool onlyRead, string system, bool hidden) { if (ReadOnly == true) { throw new Exception("The DvD has been blocked sorry"); } if (FileList.Count > 0) { foreach (File element in FileList) { if (element.FileName.ToLower() == fileName.ToLower()) { throw new Exception("This file is already in the file list"); } } } if (fileSize / 1048576 > this.FreeCapacity) { throw new Exception("There is not enough free capacity"); } else if (fileSize / 1048576 <= this.FreeCapacity) { File addfile = new File(fileName, fileSize, onlyRead, system, hidden); FileList.Add(addfile); return; } }
public void TestAddFileNotFound() { //A file name that does not contain wildcards and does not exist will throw FileNotFound FileList list = new FileList(); list.RecurseFolders = false; list.Add(Path.Combine(@"C:\", Guid.NewGuid().ToString())); }
public void Init() { dirInfo = new DirectoryInfo(XmlFilePath); foreach (var fi in dirInfo.GetFiles()) { FileList.Add(fi.Name); } }
private void AddImages(IEnumerable <string> files) { foreach (var file in files) { var newRecord = new FileRecord(file); newRecord.TargetTime = DefaultTimer; FileList.Add(newRecord); } }
public override IOutputStream CreateFile(string fileName) { IOutputStream outputStream = new LocalFileOutputStream(string.Format("{0}\\{1}", Location, fileName)); if(FileList.Select(x=>x.ToLower()).Contains(fileName.ToLower())) { FileList.Add(fileName); } return outputStream; }
private FileList selectFiles(List <string> files, string rootFolder) { FileList fileList = new FileList(rootFolder); int loc = fileList.Add(@"B:\Programming\VisualStudioProjects\PDFMerge1\PDFMerge1\Study\Cover Page.pdf"); foreach (String file in files) { fileList.Add(ROOT_FOLDER + file); } // add a couple of extra test items fileList.Add("this is junk"); fileList.Move(loc, 0); return(fileList); }
private void _addOne(string file) { var item = new FileItem(file); if (Regex.IsMatch(item.Extension, Filter)) { FileList.Add(item); } }
protected virtual void refreshFileList() { FileList.Clear(); foreach (var item in _directoryInformation.GetFiles()) { FileList.Add(item.Name); } }
public bool Add(string newFilePath) { if (System.IO.File.Exists(newFilePath) && Path.GetExtension(newFilePath).IsInputType() && !FileList.Contains(newFilePath)) { FileList.Add(newFilePath); return(true); } return(false); }
/// <summary> /// 添加单个文件 /// </summary> /// <param name="path"></param> private void _addOne(string path) { var item = new FileItem(path); if (FileList.Contains(item)) { return; } FileList.Add(item); }
FileList BuildFileList(IEnumerable <string> files, long len = 0) { FileList list = new FileList(); foreach (var file in files) { list.Add(file, len); } return(list); }
private void AddFileWithoutDocNo(string fileName) { if (Path.GetFileName(fileName).StartsWith("-")) { FileList.Add(new FileInforMation() { originalFilpath = fileName }); } }
// Insert logic for processing found files here. public static void ProcessFile(string path) { //Console.WriteLine("Processed file '{0}'.", path); if (Path.GetExtension(path) == ".pdf") { if (!FileList.Contains(path)) { FileList.Add(path); } } }
/// <summary> /// Adds files from a specific folder. The folder relative location is used to avoid messing up the folder structure. /// </summary> /// <param name="sourceLocation">The location of the source folder</param> /// <param name="SourceFolderRelativeLocation">The relatice location of the source folder.</param> public void AddFilesFromAFolder(string sourceLocation, string SourceFolderRelativeLocation) { var tempList = PullFiles(Path.Combine(sourceLocation, SourceFolderRelativeLocation)); foreach (string fileEntry in tempList) { ArchiveMemoryStream.CreateEntryFromFile(fileEntry, fileEntry.Replace(sourceLocation + GetFolderCharacter(), ""), CompressionLevel.NoCompression); FileList.Add(fileEntry.Replace(sourceLocation + GetFolderCharacter(), "")); } }
public void OpenFolder() { string[] Files = Directory.GetFiles("Save/", "*.ead"); foreach (string S in Files) { FileList.Add(new EadFile() { FileName = S.Split('/')[1] }); } }
/// <summary> /// Adds files from a specific folder. /// </summary> /// <param name="source">The location of the source folder.</param> public void AddFilesFromAFolder(string source) { var tempList = PullFiles(source); foreach (string fileEntry in tempList) { ArchiveMemoryStream.CreateEntryFromFile(fileEntry, fileEntry.Replace(source + GetFolderCharacter(), ""), CompressionLevel.NoCompression); FileList.Add(fileEntry.Replace(source + GetFolderCharacter(), "")); } }
public void AddFile(string file) { if (!FileExists(file)) { FileList.Add(file); } else { throw new Exception(string.Format("El archivo {0} ya existe", file)); } }