/// <summary> /// Flushes any pending data and closes output file. If writing to an OutputStream, the stream is not /// </summary> /// <returns>true is success</returns> public bool Finish() { if (!Started) { return(false); } bool ok = true; Started = false; try { Fs.WriteByte(0x3b); // gif trailer Fs.Flush(); if (closeStream) { Fs.Close(); } } catch (IOException e) { ok = false; } // reset for subsequent use transIndex = 0; Fs = null; image = null; pixels = null; indexedPixels = null; colorTab = null; closeStream = false; firstFrame = true; return(ok); }
public void Run() { Writer = XmlWriter.Create(Fs, XmlSettings); Writer.WriteStartDocument(); WriteServices(); Writer.WriteEndDocument(); Writer.Close(); Fs.Close(); }
private void check_permission() { r_p = new string[] { "√", "√", "√", "√", "√", "√", "√", "√" }; w_p = new string[] { "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>" }; d_p = new string[] { "<font color=red>X</font>", "-", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "<font color=red>X</font>", "-" }; string[] paths = new string[] { "/", "web.config", "/e/d/", "/e/zdyform/", "/e/zdymodel/", "/e/zdytag/", "/e/upload/", "/e/database/" }; System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("GB2312"); FileStream Fs; StreamWriter rw; string cfiles = ""; for (int i = 0; i < paths.Length; i++) { if (paths[i] == "web.config") { cfiles = Server.MapPath("/web.config"); } else { cfiles = Server.MapPath(paths[i] + "c.txt"); } try { if (paths[i] == "web.config") { Fs = new FileStream(cfiles, FileMode.Append, FileAccess.Write); rw = new StreamWriter(Fs, encoding); rw.Write(""); } else { Fs = new FileStream(cfiles, FileMode.Create, FileAccess.Write); rw = new StreamWriter(Fs, encoding); rw.Write(paths[i]); } rw.Flush(); rw.Close(); Fs.Close(); w_p[i] = "√"; } catch {} if (File.Exists(cfiles) && paths[i] != "web.config" && paths[i] != "/e/database/") { try { File.Delete(cfiles); d_p[i] = "√"; } catch {} } } }
protected virtual void Dispose(bool disposing) { if (Disposed) { return; } if (disposing) { Fs?.Close(); } Fs = null; Disposed = true; }
public void ReceiveFile(string FileName, long FileLength) { FileStream Fs = null; try { byte[] RecData = new byte[FilePiece.data_size]; int RecBytes; client = Listener.AcceptTcpClient(); netstream = client.GetStream(); if (FileName != string.Empty) { Fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write); while ((RecBytes = netstream.Read(RecData, 0, RecData.Length)) > 0) { Fs.Write(RecData, 0, RecBytes); } Fs.Close(); netstream.Close(); client.Close(); } } catch (IOException ex) { Fs.Close(); DestroyConnection(); Message = "COPY: Not enough space on disk: " + ex; Console.WriteLine(Message); error = true; } catch { error = true; Fs.Close(); } }
private static void ScanAFile(FileInfo f) { Debug.WriteLine(f.FullName); Stream fStream; int errorCode = IO.FileStream.OpenFileRead(f.FullName, out fStream); if (errorCode != 0) { return; } int offset; FileType foundFileType = FileHeaderReader.GetType(fStream, out offset); RvFile tFile = UnCompFiles.CheckSumRead(fStream, offset); tFile.AltType = foundFileType; if (foundFileType == FileType.CHD) { // need to validate check the CHD file } // test if needed. FindStatus res = fileneededTest(tFile); if (res == FindStatus.FileNeededInArchive) { Debug.WriteLine("Reading file as " + tFile.SHA1); GZip gz = new GZip(); gz.crc = tFile.CRC; gz.md5Hash = tFile.MD5; gz.sha1Hash = tFile.SHA1; gz.uncompressedSize = tFile.Size; Stream ds; IO.FileStream.OpenFileRead(f.FullName, out ds); string outfile = Getfilename(tFile.SHA1); gz.WriteGZip(outfile, ds, false); ds.Close(); ds.Dispose(); tFile.DBWrite(); } if (foundFileType == FileType.ZIP) { ZipFile fz = new ZipFile(); fz.ZipFileOpen(f.FullName, f.LastWriteTime, true); { for (int i = 0; i < fz.LocalFilesCount(); i++) { // this needs to go back into the Zip library. int Buffersize = 1024 * 1024; byte[] _buffer = new byte[Buffersize]; Stream stream; ulong streamSize; ushort compressionMethod; fz.ZipFileOpenReadStream(i, false, out stream, out streamSize, out compressionMethod); string file = @"C:\RomVaultX\" + Guid.NewGuid(); Stream Fs; IO.FileStream.OpenFileWrite(file, out Fs); ulong sizetogo = streamSize; while (sizetogo > 0) { int sizenow = sizetogo > (ulong)Buffersize ? Buffersize : (int)sizetogo; stream.Read(_buffer, 0, sizenow); Fs.Write(_buffer, 0, sizenow); sizetogo -= (ulong)sizenow; } Fs.Close(); stream.Close(); FileInfo fi = new FileInfo(file); ScanAFile(fi); File.Delete(file); } } } if (foundFileType == FileType.GZ) { } }
public void StartRending(System.IO.DirectoryInfo baseTempDir, List <VocalUtau.Calculators.BarkerCalculator.BgmPreRender> BList, string RendToWav = "") { _IsRending = true; _ExitRending = false; if (RendingStateChange != null) { RendingStateChange(this); } string ProcessIDStr = Process.GetCurrentProcess().Id.ToString(); DirectoryInfo tempDir = baseTempDir.CreateSubdirectory("temp"); DirectoryInfo cacheDir = baseTempDir.CreateSubdirectory("cache"); string TrackFileName = tempDir.FullName + "\\Bgm_" + CacheSignal + ".wav"; FileStream Fs; headSize = InitFile(out Fs, TrackFileName); Semaphore semaphore = new Semaphore(1, 1, "VocalUtau.WavTool." + ProcessIDStr + ".Bgm_" + CacheSignal); for (int i = 0; i < BList.Count; i++) { if (BList[i].DelayTime > 0) { int ByteTime = (int)(IOHelper.NormalPcmMono16_Format.AverageBytesPerSecond * BList[i].DelayTime); ByteTime -= ByteTime % 2; byte[] byteL = new byte[ByteTime]; Array.Clear(byteL, 0, ByteTime); Fs.Write(byteL, 0, ByteTime); } semaphore.WaitOne(); try { int ByteTime = (int)(IOHelper.NormalPcmMono16_Format.AverageBytesPerSecond * BList[i].PassTime); ByteTime -= ByteTime % 2; using (NAudio.Wave.AudioFileReader reader = new NAudio.Wave.AudioFileReader(BList[i].FilePath)) { int JumpLoops = ByteTime / 2; using (NAudio.Wave.Wave32To16Stream w16 = new NAudio.Wave.Wave32To16Stream(reader)) { using (NAudio.Wave.WaveStream wfmt = new NAudio.Wave.BlockAlignReductionStream(w16)) { using (NAudio.Wave.WaveStream wout = new NAudio.Wave.WaveFormatConversionStream(IOHelper.NormalPcmMono16_Format, wfmt)) { while (wout.Position < wout.Length) { if (_ExitRending) { break; } byte[] by = new byte[2]; int rd = wout.Read(by, 0, 2); if (JumpLoops > 0) { JumpLoops--; } else { Fs.Write(by, 0, 2); } /* for (int w = 1; w < w16.WaveFormat.Channels; w++) * { * int rdr = w16.Read(by, 0, 2); * }*/ } } } } } } catch {; } Fs.Flush(); semaphore.Release(); if (_ExitRending) { break; } } _IsRending = false; long total = Fs.Length; byte[] head = IOHelper.GenerateHead((int)(total - headSize)); Fs.Seek(0, SeekOrigin.Begin); Fs.Write(head, 0, head.Length); Fs.Flush(); Fs.Close(); _ExitRending = false; if (RendingStateChange != null) { RendingStateChange(this); } if (RendToWav != "") { File.Copy(TrackFileName, RendToWav, true); try { File.Delete(TrackFileName); } catch {; } } }
//关闭词法分析器 public static void CloseScanner() { Fs?.Close(); }
public void StartRending(System.IO.DirectoryInfo baseTempDir, List <VocalUtau.Calculators.NoteListCalculator.NotePreRender> NList, string RendToWav = "") { _IsRending = true; _ExitRending = false; if (RendingStateChange != null) { RendingStateChange(this); } string ProcessIDStr = Process.GetCurrentProcess().Id.ToString(); DirectoryInfo tempDir = baseTempDir.CreateSubdirectory("temp"); DirectoryInfo cacheDir = baseTempDir.CreateSubdirectory("cache"); string TrackFileName = tempDir.FullName + "\\Track_" + CacheSignal + ".wav"; FileStream Fs; headSize = InitFile(out Fs, TrackFileName); Semaphore semaphore = new Semaphore(1, 1, "VocalUtau.WavTool." + ProcessIDStr + ".Track_" + CacheSignal); ResamplerCacheDic.Clear(); Task t = Task.Factory.StartNew(() => { DoResampler(cacheDir, NList); }); for (int i = 0; i < NList.Count; i++) { while (!ResamplerCacheDic.ContainsKey(i)) { if (_ExitRending) { break; } System.Threading.Thread.Sleep(100); } if (_ExitRending) { break; } string MidFileName = ResamplerCacheDic[i]; string wavStr = String.Join(" ", NList[i].WavtoolArgList); double delay = 0; if (NList[i].passTime > 0) { delay = NList[i].passTime; } VocalUtau.WavTools.Model.Args.ArgsStruct parg = VocalUtau.WavTools.Model.Args.ArgsParser.parseArgs(NList[i].WavtoolArgList, false); Console.WriteLine("WaveAppending[" + i.ToString() + "/" + (NList.Count - 1).ToString() + "]:" + NList[i].Note + (NList[i].Note == "{R}"?"":" - " + NList[i].OtoAtom.PhonemeSymbol)); semaphore.WaitOne(); try { WavAppender.AppendWork(Fs, MidFileName, parg.Offset, parg.Length, parg.Ovr, parg.PV, delay); } catch {; } Fs.Flush(); semaphore.Release(); } _IsRending = false; long total = Fs.Length; byte[] head = IOHelper.GenerateHead((int)(total - headSize)); Fs.Seek(0, SeekOrigin.Begin); Fs.Write(head, 0, head.Length); Fs.Flush(); Fs.Close(); t.Wait(); _ExitRending = false; if (RendingStateChange != null) { RendingStateChange(this); } if (RendToWav != "") { File.Copy(TrackFileName, RendToWav, true); try { File.Delete(TrackFileName); } catch {; } } }
//关闭词法分析器 public static void CloseScanner() { Fs?.Close();//语法糖,如果Fs不为null,关闭文件 }