//split line by char; public void readLinesFromFile(string file, char readUntilToChar, pafap_lists pl) { String[] paths; int sep; int iLine = 0; int errornum = 0; try { StreamReader sr = new StreamReader(file); do { Line = sr.ReadLine(); if (Line == null) { continue; } iLine++; Line = Line.Trim(); if (Line.Length == 0) { continue; } sep = Line.IndexOf(readUntilToChar); if (sep < 0) { errornum++; errors = "readLineFromFile error!"; continue; } paths = new String[2]; paths[0] = Line.Substring(0, sep); paths[1] = Line.Substring(sep + 1, Line.Length - sep - 1); source = paths[0]; destination = paths[1]; lp.source = source; lp.destination = destination; pl.l.Add(lp); }while (Line != null); sr.Close(); } catch (Exception e) { errors = "readLineFromFile error: " + e.Message; } finally { if (source.Length > 0 && destination.Length > 0) { isParsed = true; } } }
private void Copier_DoWork(object sender, DoWorkEventArgs e) { pafap_files pf = new pafap_files(); pafap_lists pl = new pafap_lists(); list = pafap_global.Init.listfile; tmplist = pafap_global.Init.tmplistfile; log = pafap_global.Init.logfile; do { if (!pf.checkIfIsOpen(list)) { pf.makeTempFile(list, tmplist); } if (!pf.checkIfIsOpen(list)) { pf.clearFile(list); } pl.init(); pf.readLinesFromFile(tmplist, '>', pl); nrOFfilesCopied = pl.l.Count; int findex = 0; start = DateTime.Now; foreach (pafap_files.loadpath plp in pl.l) { try { findex++; FileInfo fis = new FileInfo(plp.source); FileInfo fid = new FileInfo(plp.destination + Path.GetFileName(plp.source)); using (FileStream sourceStream = new FileStream(plp.source, FileMode.Open, FileAccess.Read)) { byte[] buffer = new byte[64 * 1024]; using (FileStream destStream = new FileStream(plp.destination + Path.GetFileName(plp.source), FileMode.Create)) { int j; while ((j = sourceStream.Read(buffer, 0, buffer.Length)) > 0) { destStream.Write(buffer, 0, j); this.Invoke(OnChange, new object[] { new UIProgress(plp.source, plp.destination, sourceStream.Position, fis.Length, findex) }); } } } } catch (Exception ex) { UIError err = new UIError(ex, plp.source); this.Invoke(OnError, new object[] { err }); if (err.result == DialogResult.Cancel) { break; } } if (pf.CheckFileHasCopied(plp.destination + Path.GetFileName(plp.source))) { pf.LogFile(plp.destination + Path.GetFileName(plp.source) + "Copied!", log); } } if (done) { pf.clearFile(tmplist); } pl.l.Clear(); } while (!pf.checkIsEmpty(list)); }