public static CreateFile ( string pathName ) : StreamWriter, | ||
pathName | string | |
return | StreamWriter, |
public void CreateIcon() { if (Icon.IsNotNullOrEmpty()) { FileUtil.CreateFile(Constant.Server.MapPath($"~/{SiteName}/icon.png"), Client.GetData($"http://{_authorizedAddress}/{Icon}")); } }
/// <summary>Unpacks to file.</summary> /// <param name="args">The arguments.</param> /// <param name="file">The file.</param> private static void UnpackToFile(UploadArgs args, HttpPostedFile file) { Assert.ArgumentNotNull((object)args, "args"); Assert.ArgumentNotNull((object)file, "file"); string filename = FileUtil.MapPath(TempFolder.GetFilename("temp.zip")); file.SaveAs(filename); using (ZipReader zipReader = new ZipReader(filename)) { foreach (ZipEntry entry in zipReader.Entries) { string str = FileUtil.MakePath(args.Folder, entry.Name, '\\'); if (entry.IsDirectory) { Directory.CreateDirectory(str); } else { if (!args.Overwrite) { str = FileUtil.GetUniqueFilename(str); } Directory.CreateDirectory(Path.GetDirectoryName(str)); lock (FileUtil.GetFileLock(str)) FileUtil.CreateFile(str, entry.GetStream(), true); } } } }
/// <summary> /// 以字节流的形式载入资源 /// </summary> private IEnumerator LoadBundleAsync(string bundleName, string bundleVersion, BundleLoadMethod method, bool saveBundle = false) { string bundlePath; var container = new BundleContainer(); switch (method) { case BundleLoadMethod.File_StreamingBundle: bundlePath = @Path.Combine(Application.streamingAssetsPath, bundleName); break; case BundleLoadMethod.File_LocalBundle: bundlePath = pather.GetLocalBundlePath(bundleName, bundleVersion); break; default: bundlePath = pather.GetServeBundlePath(bundleName, bundleVersion); break; } yield return(ExecuteLoadBundleAsync(bundlePath, method, container)); onLoadEveryComplete(container.assetBundle); if (saveBundle && container.bytes != null) { var filePath = pather.GetLocalBundlePath(bundleName, bundleVersion); FileUtil.CreateFile(filePath, container.bytes); } }
static void DelegateFactory(CommandLine command, string[] args) { var output = Launch.GetPath("-output", "-o"); var dll = command.GetValue("-dll"); var assembly = dll.isNullOrWhiteSpace() ? null : Assembly.LoadFile(Path.Combine(CurrentDirectory, dll)); var strClass = command.GetValue("-class"); if (strClass.isNullOrWhiteSpace()) { throw new Exception("找不到 -class 参数"); } var generate = new GenerateScorpioDelegate(); var classNames = strClass.Split(";"); foreach (var className in classNames) { var clazz = GetType(assembly, className, null); if (clazz == null) { throw new Exception($"找不到 class, 请输入完整类型或检查类名是否正确 : {className}"); } generate.AddType(clazz); } FileUtil.CreateFile(output, generate.Generate(0)); Logger.info($"生成Delegate仓库 {output}"); }
/// <summary> /// Unpacks to file. /// </summary> /// <param name="args">The arguments.</param> /// <param name="file">The file.</param> private static void UnpackToFile(UploadArgs args, HttpPostedFile file) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(file, "file"); string filename = FileUtil.MapPath(TempFolder.GetFilename("temp.zip")); file.SaveAs(filename); using (ZipReader zipReader = new ZipReader(filename)) { foreach (ZipEntry current in zipReader.Entries) { string text = FileUtil.MakePath(args.Folder, current.Name, '\\'); if (current.IsDirectory) { System.IO.Directory.CreateDirectory(text); } else { if (!args.Overwrite) { text = FileUtil.GetUniqueFilename(text); } System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(text)); lock (FileUtil.GetFileLock(text)) { FileUtil.CreateFile(text, current.GetStream(), true); } } } } }
public void CreateFiles(Table table) { foreach (var row in table.Rows) { FileUtil.CreateFile(row["Folder path"], row["File name"]); } }
private string UploadFile(FileUpload info) { string filePath = GetFilePath(info); string relativeSavePath = filePath.Replace(info.BasePath, ""); string serverRealPath = filePath; if (!Path.IsPathRooted(filePath)) { serverRealPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, filePath); } serverRealPath = GetRightFileName(serverRealPath, 1); relativeSavePath = relativeSavePath.Substring(0, relativeSavePath.LastIndexOf(info.FileName)) + FileUtil.GetFileName(serverRealPath); info.FileName = FileUtil.GetFileName(serverRealPath); FileUtil.CreateFile(serverRealPath, info.FileData); bool success = FileUtil.IsExistFile(serverRealPath); if (success) { return(relativeSavePath); } else { return(string.Empty); } }
/// <summary> /// 把文件保存到指定目录,并返回相对基础目录的路径 /// </summary> /// <param name="info">文件上传信息</param> /// <returns>成功返回相对基础目录的路径,否则返回空字符</returns> private string UploadFile(FileUploadInfo info) { //检查输入及组合路径 string filePath = GetFilePath(info); string relativeSavePath = filePath.Replace(info.BasePath, "").Trim('\\');//替换掉起始目录即为相对路径 string serverRealPath = filePath; if (!Path.IsPathRooted(filePath)) { serverRealPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, filePath); } //通过实际文件名去查找对应的文件名称 serverRealPath = GetRightFileName(serverRealPath, 1); //当文件已存在,而重新命名时,修改Filename及relativeSavePath relativeSavePath = relativeSavePath.Substring(0, relativeSavePath.LastIndexOf(info.FileName)) + FileUtil.GetFileName(serverRealPath); info.FileName = FileUtil.GetFileName(serverRealPath); //根据实际文件名创建文件 FileUtil.CreateFile(serverRealPath, info.FileData); bool success = FileUtil.IsExistFile(serverRealPath); if (success) { return(relativeSavePath); } else { return(string.Empty); } }
/// <summary> /// 查找不适用文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFindNotSetFile_Click(object sender, EventArgs e) { string path = txtPath.Text.Trim(); if (string.IsNullOrEmpty(path)) { path = FileDialogHelper.OpenDir(); } if (!DirectoryUtil.IsExistDirectory(path)) { MessageDxUtil.ShowTips("文件路径不可用"); return; } string recordFileName = "\\" + "不适用文件.txt"; if (FileUtil.FileIsExist(path + recordFileName)) { FileUtil.DeleteFile(path + recordFileName); } FileUtil.CreateFile(path + recordFileName); string[] allFiles = DirectoryUtil.GetAllFileNames(path); foreach (var file in allFiles) { FileInfo fileInfo = new FileInfo(file); if (fileInfo.Name.Contains("不适用")) { FileUtil.AppendText(path + recordFileName, string.Format("{0}\t\t\t{1}\r\n", fileInfo.Name, fileInfo.FullName), Encoding.UTF8); } } MessageDxUtil.ShowTips("操作完成"); }
public static void SetConfig(PROGRAM program, string key, string value, ConfigFile file) { ScorpioIni config = GetConfig(file); config.Set(program == PROGRAM.NONE ? "" : program.ToString(), key, value); FileUtil.CreateFile(WorkspaceDirectory + file.ToString() + ".ini", config.GetString()); }
static void Interface(CommandLine command, string[] args) { var output = perform.GetPath(ParameterOutput); var strClass = command.GetValue(ParameterClass); if (strClass.isNullOrWhiteSpace()) { throw new Exception("找不到 -class 参数"); } var dll = command.GetValue(ParameterDll); var assembly = dll.isNullOrWhiteSpace() ? null : Assembly.LoadFile(Path.Combine(CurrentDirectory, dll)); var classNames = strClass.Split(";"); foreach (var className in classNames) { var clazz = GetType(assembly, className, null); if (clazz == null) { throw new Exception($"找不到 class, 请输入完整类型或检查类名是否正确 : {className}"); } var generate = new GenerateScorpioInterface(clazz); var outputFile = Path.Combine(output, generate.ScorpioClassName + ".cs"); FileUtil.CreateFile(outputFile, generate.Generate()); Logger.info($"生成Interface类 {className} -> {outputFile}"); } }
public void onBtnClickOk() { if (TextAudioPath.text != "" && TextExcelPath.text != "" && TextOutPutPath.text != "") { /* * 初始化任务 */ if (!TaskManager.Instance.InitByExcel(TextExcelPath.text, TextOutPutPath.text)) { Debug.Log("excel == null"); return; } /* * 创建源数据保存文件到导出路径 */ SourceDataConfig s = new SourceDataConfig(); s.StrAudioSourcePath = TextAudioPath.text; s.StrExcelPath = TextExcelPath.text; string strJson = JsonUtility.ToJson(s); FileUtil.CreateFile(TextOutPutPath.text, FILE_NAME_SOURCE_CONFIG, strJson); /* * 跳转到翻译界面 */ ModuleParamToProcess mpp = new ModuleParamToProcess( TextExcelPath.text, TextAudioPath.text, TextOutPutPath.text ); CacheCanvasManager.StartModule(CanvasManager.ModuleType.E_PROCESS, mpp); } }
public void CreateData(string name, byte[] data) { if (string.IsNullOrEmpty(DataDirectory)) { return; } FileUtil.CreateFile(name + ".data", data, false, DataDirectory.Split(';')); }
public void CreateFile(string name, string context) { if (string.IsNullOrEmpty(CodeDirectory)) { return; } FileUtil.CreateFile(GetFile(name), context, Bom, CodeDirectory.Split(';')); }
public void SaveResource() { Resource.Split(',').Each(t => { var name = Path.GetFileName(t.ToString()); FileUtil.CreateFile(Constant.Server.MapPath($"~/{SiteName}/resource/{name}"), Client.GetData($"http://{_authorizedAddress}/{t.ToString()}")); }); }
public void SetEffectPlayAudio(bool isplay) { mIsPlayAudioEff = isplay; string str = "{\"music\":{" + "\"bgm\":" + (mIsPlayAudioBgm ? 1 : 0) + "," + "\"effet\":" + (mIsPlayAudioBgm ? 1 : 0) + "}}"; FileUtil.CreateFile(Application.persistentDataPath, "musicdata.txt", str); }
protected virtual void CreateDSNFile() { string dsnFile = Path.Combine(GlobalSetting.Config.TempDirectory, "Demo.dsn"); FileUtil.CreateFile(dsnFile); FileUtil.AppendText(dsnFile, "124", true); FileUtil.AppendText(dsnFile, "222", true); FileUtil.AppendText(dsnFile, "2234", true); }
public void SaveTasksConfig() { TasksConfig tc = new TasksConfig(); tc.ListTasks = listTasks_; string strJson = JsonUtility.ToJson(tc); FileUtil.CreateFile(strOutPutPath_, FILE_NAME_TASKS_CONFIG, strJson); }
/// <summary> /// 是否播放音效 /// </summary> /// <param name="isplay"></param> public void SetPlayEffectAudio(bool isplay) { IsPlayAudioEff = isplay; //根据是否播放背景音乐和是否播放音效来保存音乐数据 string str = "{\"music\":{" + "\"bgm\":" + (IsPlayAudioBgm ? 1 : 0) + "," + "\"effect\":" + (IsPlayAudioEff ? 1 : 0) + "}}"; FileUtil.CreateFile(Application.persistentDataPath, "musicdata.txt", str); }
void InsertPath(string path) { paths.Remove(path); paths.Insert(0, path); if (!listPaths.Items.Contains(path)) { listPaths.Items.Add(path); } FileUtil.CreateFile(workspaceConfig, string.Join(";", paths.ToArray())); }
private void btnDownload_Click(object sender, EventArgs e) { if (this.listView1.CheckedItems.Count == 0) { MessageDxUtil.ShowTips("请勾选下载的文件!"); return; } StringBuilder sb = new StringBuilder(); string path = FileDialogHelper.OpenDir(); if (!string.IsNullOrEmpty(path)) { DirectoryUtil.AssertDirExist(Path.GetDirectoryName(path)); #region 载保存图片 bool hasError = false; foreach (ListViewItem item in this.listView1.CheckedItems) { if (item != null && item.Tag != null) { string id = item.Tag.ToString(); try { FileUploadInfo fileInfo = BLLFactory <FileUpload> .Instance.Download(id); if (fileInfo != null && fileInfo.FileData != null) { string filePath = Path.Combine(path, fileInfo.FileName); FileUtil.CreateFile(filePath, fileInfo.FileData); } } catch (Exception ex) { hasError = true; sb.Append(ex.Message + "\r\n"); LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmAttachmentGroupView)); } } } #endregion if (hasError) { MessageDxUtil.ShowError(sb.ToString()); } else { System.Diagnostics.Process.Start(path); } } }
private void checkDefault_CheckedChanged(object sender, EventArgs e) { if (this.checkDefault.Checked) { FileUtil.CreateFile(workspaceDefault, "1"); } else { FileUtil.CreateFile(workspaceDefault, "0"); } }
static void Fast(CommandLine command, string[] args) { var output = Launch.GetPath("-output", "-o"); var dll = command.GetValue("-dll"); var assembly = dll.isNullOrWhiteSpace() ? null : Assembly.LoadFile(Path.Combine(CurrentDirectory, dll)); var strClass = command.GetValue("-class"); if (strClass.isNullOrWhiteSpace()) { throw new Exception("找不到 -class 参数"); } var strExtension = command.GetValue("-extension"); ClassFilter filter = null; var strFilter = command.GetValue("-filter"); if (!strFilter.isNullOrWhiteSpace()) { var filterType = GetType(assembly, strFilter, typeof(ClassFilter)); if (filterType != null) { filter = (ClassFilter)Activator.CreateInstance(filterType); } } var extensions = new List <Type>(); if (!strExtension.isNullOrWhiteSpace()) { foreach (var cl in strExtension.Split(';')) { extensions.Add(GetType(assembly, cl, null)); } } var classNames = strClass.Split(";"); foreach (var className in classNames) { var clazz = GetType(assembly, className, null); if (clazz == null) { throw new Exception($"找不到 class, 请输入完整类型或检查类名是否正确 : {className}"); } var generate = new GenerateScorpioClass(clazz); generate.SetClassFilter(filter); foreach (var ex in extensions) { generate.AddExtensionType(ex); } var outputFile = Path.Combine(output, generate.ScorpioClassName + ".cs"); FileUtil.CreateFile(outputFile, generate.Generate()); Logger.info($"生成快速反射类 {className} -> {outputFile}"); } }
public void SaveTemp() { DeleteTemp(); var tuple = GetPath(); if (tuple.IsNotNull()) { var head = tuple.Item2; head = Content.Contains("include=true") ? string.Empty : head; FileUtil.CreateFile(tuple.Item1, $"{head}{Content}"); } }
/* * 保存可行方案到本地 */ public void SaveResultToLocalByOutPutPath(string outputPath) { TaskResultsGroup g = new TaskResultsGroup(); g.ListResults = ListTaskResult; string strJson = JsonUtility.ToJson(g); FileUtil.CreateFile( outputPath + "\\" + FOLDER_NAME_RESULTS_CONFIG , FILE_NAME_PRE + StrTaskWord, strJson); }
private void saveAudioPartConfig() { /* * 保存音频片段配置信息 */ AudioPartConfig audioPart = new AudioPartConfig(); audioPart.ListAudioParts = listAudioParts_; string strJson = JsonUtility.ToJson(audioPart); FileUtil.CreateFile(strOutPutPath_, AUDIO_PART_CONFIG_FILE_NAME, strJson); }
private void btnDownload_Click(object sender, EventArgs e) { if (this.listView1.CheckedItems.Count == 0) { MessageDxUtil.ShowTips("请勾选下载的文件!"); return; } string path = FileDialogHelper.OpenDir(); if (!string.IsNullOrEmpty(path)) { DirectoryUtil.AssertDirExist(Path.GetDirectoryName(path)); #region 载保存图片 bool hasError = false; foreach (ListViewItem item in this.listView1.CheckedItems) { if (item != null && item.Tag != null) { string id = item.Tag.ToString(); try { FileUploadInfo fileInfo = BLLFactory <FileUpload> .Instance.Download(id); if (fileInfo != null && fileInfo.FileData != null) { string filePath = Path.Combine(path, fileInfo.FileName); FileUtil.CreateFile(filePath, fileInfo.FileData); } } catch (Exception ex) { LogTextHelper.Error(ex); hasError = true; } } } #endregion if (hasError) { MessageDxUtil.ShowError("保存文件出现错误。具体请查看日志文件!"); } else { System.Diagnostics.Process.Start(path); } } }
private void simpleButton3_Click(object sender, EventArgs e) { string path = txtPath.Text.Trim(); if (string.IsNullOrEmpty(path)) { path = FileDialogHelper.OpenDir(); } string fileRecord = "F:\\oldfile.txt"; string fileNewReocrd = "F:\\newfile.txt"; if (FileUtil.IsExistFile(fileRecord)) { FileUtil.DeleteFile(fileRecord); } FileUtil.CreateFile(fileRecord); if (FileUtil.IsExistFile(fileNewReocrd)) { FileUtil.DeleteFile(fileNewReocrd); } FileUtil.CreateFile(fileNewReocrd); Int32 copyCount = 0; if (!string.IsNullOrEmpty(path)) { string[] files = DirectoryUtil.GetFileNames(path, "*", true); foreach (var file in files) { FileUtil.AppendText(fileRecord, file + "\r\n", Encoding.UTF8); string oldfilerelatefile = file.Replace(path + "\\", ""); string newfllerelatefile = oldfilerelatefile.Replace("\\", "_"); if (FileUtil.IsExistFile(file) && oldfilerelatefile != newfllerelatefile) { File.Move(file, path + "\\" + newfllerelatefile); copyCount++; } } files = DirectoryUtil.GetFileNames(path, "*", true); foreach (var file in files) { FileUtil.AppendText(fileNewReocrd, file + "\r\n", Encoding.UTF8); } } MessageDxUtil.ShowTips("操作完成, 一共成功复制" + copyCount + "个文件"); }
private void CreateThumbnail() { var mediaData = new MediaData(this.mediaItem); MediaStream thumbnailStream = mediaData.GetThumbnailStream(); if (thumbnailStream == null) { return; } string file = GetThumbnailFilename(); FileUtil.EnsureFileFolder(file); FileUtil.CreateFile(FileUtil.MapPath(file), thumbnailStream.Stream, true); }
/// <summary> /// 从服务器下载并保存新资源包 /// </summary> /// <param name="bundleName"></param> /// <param name="bundleVersion"></param> /// <returns></returns> private IEnumerator DownloadAndSaveBundle(string bundleName, string bundleVersion) { //获取服务器请求url var requestUrl = pather.GetServeBundlePath(bundleName, bundleVersion); var webBytesLoadRequest = UnityWebRequest.Get(requestUrl); yield return(webBytesLoadRequest.SendWebRequest()); byte[] bs = webBytesLoadRequest.downloadHandler.data; //获取本地包存储路径 var localPath = pather.GetLocalBundlePath(bundleName, bundleVersion); //将服务器获得的新包数据保存到本地 FileUtil.CreateFile(localPath, bs); }