本文整理汇总了C#中IAbsoluteFilePath.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IAbsoluteFilePath.ToString方法的具体用法?C# IAbsoluteFilePath.ToString怎么用?C# IAbsoluteFilePath.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAbsoluteFilePath
的用法示例。
在下文中一共展示了IAbsoluteFilePath.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryCheckUac
async Task<bool> TryCheckUac(IAbsoluteDirectoryPath mp, IAbsoluteFilePath path) {
Exception ex;
try {
mp.MakeSurePathExists();
if (path.Exists)
File.Delete(path.ToString());
using (File.CreateText(path.ToString())) {}
File.Delete(path.ToString());
return false;
} catch (UnauthorizedAccessException e) {
ex = e;
} catch (Exception e) {
this.Logger().FormattedWarnException(e);
return false;
}
var report = await UserErrorHandler.HandleUserError(new UserErrorModel("Restart the application elevated?",
$"The application failed to write to the path, probably indicating permission issues\nWould you like to restart the application Elevated?\n\n {mp}",
RecoveryCommands.YesNoCommands, null, ex)) == RecoveryOptionResultModel.RetryOperation;
if (!report)
return false;
RestartWithUacInclEnvironmentCommandLine();
return true;
}
示例2: TryDownloadAsync
async Task TryDownloadAsync(TransferSpec spec, IWebClient webClient, IAbsoluteFilePath tmpFile) {
try {
tmpFile.RemoveReadonlyWhenExists();
if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
webClient.SetAuthInfo(spec.Uri);
using (webClient.HandleCancellationToken(spec))
await webClient.DownloadFileTaskAsync(spec.Uri, tmpFile.ToString()).ConfigureAwait(false);
VerifyIfNeeded(spec, tmpFile);
_fileOps.Move(tmpFile, spec.LocalFile);
} catch (OperationCanceledException e) {
_fileOps.DeleteIfExists(tmpFile.ToString());
throw CreateTimeoutException(spec, e);
} catch (WebException ex) {
_fileOps.DeleteIfExists(tmpFile.ToString());
var cancelledEx = ex.InnerException as OperationCanceledException;
if (cancelledEx != null)
throw CreateTimeoutException(spec, cancelledEx);
if (ex.Status == WebExceptionStatus.RequestCanceled)
throw CreateTimeoutException(spec, ex);
var response = ex.Response as HttpWebResponse;
if (response == null)
throw GenerateDownloadException(spec, ex);
switch (response.StatusCode) {
case HttpStatusCode.NotFound:
throw new RequestFailedException("Received a 404: NotFound response", ex);
case HttpStatusCode.Forbidden:
throw new RequestFailedException("Received a 403: Forbidden response", ex);
case HttpStatusCode.Unauthorized:
throw new RequestFailedException("Received a 401: Unauthorized response", ex);
}
throw GenerateDownloadException(spec, ex);
}
}
示例3: SHA1FileHash
public string SHA1FileHash(IAbsoluteFilePath fileName) {
Contract.Requires<ArgumentNullException>(fileName != null);
return FileUtil.Ops.AddIORetryDialog(() => {
using (var fs = new FileStream(fileName.ToString(), FileMode.Open, FileAccess.Read, FileShare.Read))
using (var stream = new BufferedStream(fs, GetBufferSize(fs)))
using (var md5 = new SHA1CryptoServiceProvider())
return GetHash(md5.ComputeHash(stream));
}, fileName.ToString());
}
示例4: GenerateCommandLineExecution
public static IEnumerable<string> GenerateCommandLineExecution(IAbsoluteFilePath location, string executable,
params string[] desiredParams) {
var updateExe = GetUpdateExe(location);
return (updateExe != null) && updateExe.Exists
? new[] {updateExe.ToString()}.Concat(Restarter.BuildUpdateExeArguments(executable, desiredParams))
: new[] {location.ToString()}.Concat(desiredParams);
}
示例5: Gzip
public virtual string Gzip(IAbsoluteFilePath file, IAbsoluteFilePath dest = null,
bool preserveFileNameAndModificationTime = true, ITProgress status = null) {
Contract.Requires<ArgumentNullException>(file != null);
Contract.Requires<ArgumentException>(file.Exists);
var defDest = (file + ".gz").ToAbsoluteFilePath();
if (dest == null)
dest = defDest;
var cmd = $"-f --best --rsyncable --keep \"{file}\"";
if (!preserveFileNameAndModificationTime)
cmd = "-n " + cmd;
dest.RemoveReadonlyWhenExists();
var startInfo =
new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) {
WorkingDirectory = file.ParentDirectoryPath
}.Build();
var srcSize = file.FileInfo.Length;
ProcessExitResultWithOutput ret;
var predictedSize = srcSize*DefaultPredictedCompressionRatio;
using (StatusProcessor.Conditional(defDest, status, (long) predictedSize))
ret = ProcessManager.LaunchAndGrabTool(startInfo, "Gzip pack");
if (Path.GetFullPath(dest.ToString()) != Path.GetFullPath(defDest.ToString()))
FileUtil.Ops.MoveWithRetry(defDest, dest);
return ret.StandardOutput + ret.StandardError;
}
示例6: Gzip
public virtual string Gzip(IAbsoluteFilePath file, IAbsoluteFilePath dest = null,
bool preserveFileNameAndModificationTime = false) {
Contract.Requires<ArgumentNullException>(file != null);
Contract.Requires<ArgumentException>(file.Exists);
var defDest = (file + ".gz").ToAbsoluteFilePath();
if (dest == null)
dest = defDest;
var cmd = String.Format("-f --best --rsyncable --keep \"{0}\"", file);
if (!preserveFileNameAndModificationTime)
cmd = "-n " + cmd;
dest.RemoveReadonlyWhenExists();
var startInfo =
new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) {
WorkingDirectory = file.ParentDirectoryPath.ToString()
}.Build();
var ret = ProcessManager.LaunchAndGrabTool(startInfo, "Gzip pack");
if (Path.GetFullPath(dest.ToString()) != Path.GetFullPath(defDest.ToString()))
FileUtil.Ops.MoveWithRetry(defDest, dest);
return ret.StandardOutput + ret.StandardError;
}
示例7: YomaConfig
public YomaConfig(IAbsoluteFilePath inputAddonsFile, IAbsoluteFilePath inputModsFile,
IAbsoluteFilePath inputServerFile = null)
: this(
XDocument.Load(inputAddonsFile.ToString()), XDocument.Load(inputModsFile.ToString()),
inputServerFile == null ? null : XDocument.Load(inputServerFile.ToString())) {
Contract.Requires<ArgumentOutOfRangeException>(inputAddonsFile != null);
Contract.Requires<ArgumentOutOfRangeException>(inputModsFile != null);
}
示例8: UnpackUpdater
public virtual void UnpackUpdater(IAbsoluteFilePath sourceFile, IAbsoluteDirectoryPath outputFolder,
bool overwrite = false, bool fullPath = true) {
Contract.Requires<ArgumentNullException>(sourceFile != null);
Contract.Requires<ArgumentNullException>(outputFolder != null);
Generic.RunUpdater(UpdaterCommands.Unpack, sourceFile.ToString(), outputFolder.ToString(),
overwrite ? "--overwrite" : null,
fullPath.ToString());
}
示例9: PackTar
public void PackTar(IAbsoluteDirectoryPath directory, IAbsoluteFilePath outputFile) {
using (var tarStream = File.OpenWrite(outputFile.ToString()))
using (var af = WriterFactory.Open(tarStream, ArchiveType.Tar, CompressionType.None)) {
foreach (var f in directory.DirectoryInfo.EnumerateFiles("*", SearchOption.AllDirectories))
af.Write(f.FullName.Replace(directory.ParentDirectoryPath + @"\", ""), f.FullName);
// This ommits the root folder ('userconfig')
//af.WriteAll(directory.ToString(), "*", SearchOption.AllDirectories);
}
}
示例10: RunExtractPboWithParameters
public void RunExtractPboWithParameters(IAbsoluteFilePath input, IAbsoluteDirectoryPath output,
params string[] parameters) {
if (!input.Exists)
throw new IOException("File doesn't exist: " + input);
var startInfo =
new ProcessStartInfoBuilder(_extractPboBin,
BuildParameters(input.ToString(), output.ToString(), parameters)).Build();
ProcessExitResult(_processManager.LaunchAndGrabTool(startInfo));
}
示例11: CreateZip
public void CreateZip(IAbsoluteDirectoryPath directory, IAbsoluteFilePath outputFile) {
using (var arc = ZipArchive.Create()) {
foreach (var f in directory.DirectoryInfo.EnumerateFiles("*", SearchOption.AllDirectories))
arc.AddEntry(f.FullName.Replace(directory.ParentDirectoryPath + @"\", ""), f.FullName);
arc.SaveTo(outputFile.ToString(),
new ZipWriterOptions(CompressionType.Deflate) {
DeflateCompressionLevel = CompressionLevel.BestCompression
});
}
}
示例12: BiKeyPair
public BiKeyPair(IAbsoluteFilePath path) {
Contract.Requires<ArgumentNullException>(path != null);
Contract.Requires<ArgumentOutOfRangeException>(!path.FileName.Contains("@"));
var p = path.ToString().Replace(".biprivatekey", String.Empty).Replace(".bikey", String.Empty);
Location = Path.GetDirectoryName(p);
Name = Path.GetFileName(p);
CreatedAt = File.GetCreationTime(p);
PrivateFile = (p + ".biprivatekey").ToAbsoluteFilePath();
PublicFile = (p + ".bikey").ToAbsoluteFilePath();
}
示例13: TryDownloadAsync
async Task TryDownloadAsync(TransferSpec spec, IWebClient webClient, IAbsoluteFilePath tmpFile) {
try {
tmpFile.RemoveReadonlyWhenExists();
if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
webClient.SetAuthInfo(spec.Uri);
using (webClient.HandleCancellationToken(spec))
await webClient.DownloadFileTaskAsync(spec.Uri, tmpFile.ToString()).ConfigureAwait(false);
VerifyIfNeeded(spec, tmpFile);
_fileOps.Move(tmpFile, spec.LocalFile);
} catch (OperationCanceledException e) {
_fileOps.DeleteIfExists(tmpFile.ToString());
throw CreateTimeoutException(spec, e);
} catch (WebException e) {
_fileOps.DeleteIfExists(tmpFile.ToString());
var cancelledEx = e.InnerException as OperationCanceledException;
if (cancelledEx != null)
throw CreateTimeoutException(spec, cancelledEx);
if (e.Status == WebExceptionStatus.RequestCanceled)
throw CreateTimeoutException(spec, e);
GenerateDownloadException(spec, e);
}
}
示例14: UnpackGzip
public void UnpackGzip(IAbsoluteFilePath sourceFile, IAbsoluteFilePath destFile, ITProgress progress = null) {
using (var archive = GZipArchive.Open(sourceFile.ToString())) {
try {
TryUnpackArchive(destFile, progress, archive);
} catch (ZlibException ex) {
if ((ex.Message == "Not a valid GZIP stream.") || (ex.Message == "Bad GZIP header.")
|| (ex.Message == "Unexpected end-of-file reading GZIP header.")
|| (ex.Message == "Unexpected EOF reading GZIP header.")) {
var header = TryReadHeader(sourceFile);
throw new CompressedFileException(
$"The archive appears corrupt: {sourceFile}. Header:\n{header}", ex);
}
throw;
}
}
}
示例15: Unpack
public virtual void Unpack(IAbsoluteFilePath sourceFile, IAbsoluteDirectoryPath outputFolder,
bool overwrite = false, bool fullPath = true, bool force7z = false, bool checkFileIntegrity = true,
ITProgress progress = null) {
Contract.Requires<ArgumentNullException>(sourceFile != null);
Contract.Requires<ArgumentNullException>(outputFolder != null);
var ext = sourceFile.FileExtension;
if (force7z ||
SevenzipArchiveFormats.Any(x => ext.Equals(x, StringComparison.OrdinalIgnoreCase))) {
using (var extracter = new SevenZipExtractor(sourceFile.ToString()))
UnpackArchive(sourceFile, outputFolder, overwrite, checkFileIntegrity, extracter);
} else {
var options = fullPath ? ExtractOptions.ExtractFullPath : ExtractOptions.None;
using (var archive = GetArchiveWithGzWorkaround(sourceFile, ext))
UnpackArchive(outputFolder, overwrite, archive, options);
}
}