private static GetTempFileName ( string original, bool makeTempFile ) : string | ||
original | string | |
makeTempFile | bool | |
Résultat | string |
private static string GetTempFileName(string original, bool makeTempFile) {
string result=null;
if (original==null) {
result=Path.GetTempFileName();
} else {
int counter=0;
int suffixSeed=DateTime.Now.Second;
while (result==null) {
counter+=1;
string newName=string.Format("{0}.{1}{2}.tmp", original, suffixSeed, counter);
if (!File.Exists(newName)) {
if (makeTempFile) {
try {
// Try and create the file.
using (FileStream stream=File.Create(newName)) {
}
result=newName;
} catch {
suffixSeed=DateTime.Now.Second;
}
} else {
result=newName;
}
}
}
}
return result;
}
public override Stream ConvertTemporaryToFinal() { if (this.temporaryStream_ == null) { throw new ZipException("No temporary stream has been created"); } Stream result = null; string tempFileName = DiskArchiveStorage.GetTempFileName(this.fileName_, false); bool flag = false; try { this.temporaryStream_.Close(); File.Move(this.fileName_, tempFileName); File.Move(this.temporaryName_, this.fileName_); flag = true; File.Delete(tempFileName); result = File.OpenRead(this.fileName_); } catch (Exception) { result = null; if (!flag) { File.Move(tempFileName, this.fileName_); File.Delete(this.temporaryName_); } throw; } return(result); }