예제 #1
0
        private void Copier_Error(UIError err)
        {
            // Error handler
            string msg = string.Format("Error copying file {0}\n{1}\nClick OK to continue copying files", err.path, err.msg);

            err.result = MessageBox.Show(msg, "Copy error", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
        }
예제 #2
0
        private void Copier_DoWork(object sender, DoWorkEventArgs e)
        {
            long maxbytes = 0;

            foreach (FileCopier file in bank)
            {
                FileInfo info = new FileInfo(file.SourceFile);
                maxbytes += info.Length;
            }
            // Copy files
            long bytes = 0;

            foreach (FileCopier file in bank)
            {
                FileInfo info = new FileInfo(file.SourceFile);
                try
                {
                    this.BeginInvoke(OnChange, new object[] { new UIProgress(Path.GetFileName(file.SourceFile), bytes, maxbytes) });
                    File.Copy(file.SourceFile, file.DestinationFile, true);
                }
                catch (Exception ex)
                {
                    UIError err = new UIError(ex, file.SourceFile);
                    this.Invoke(OnError, new object[] { err });
                    if (err.result == DialogResult.Cancel)
                    {
                        break;
                    }
                }
                bytes += info.Length;
            }
            this.DialogResult = DialogResult.OK;
        }
예제 #3
0
파일: frmCopy.cs 프로젝트: hcl7/WhatchCopy
        private void Copier_Error(UIError err)
        {
            pafap_files pf  = new pafap_files();
            string      msg = string.Format("Copy file error: {0}\n{1}\n", err.path, err.msg);

            err.result = MessageBox.Show(msg, "Copy error", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            pf.LogFile(msg, pafap_global.Init.logfile);
        }
예제 #4
0
 public IActionResult LogError([FromBody] UIError error)
 {
     logger.LogError(error.Message);
     return(Ok());
 }
예제 #5
0
파일: frmCopy.cs 프로젝트: hcl7/WhatchCopy
        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));
        }
 public static void ShowInputError(UIError message, TextBlock control)
 {
     control.Text       = UIErrorMessages[message];
     control.Visibility = Visibility.Visible;
 }
예제 #7
0
파일: Form1.cs 프로젝트: dant0n/CopyPaste
 private void copyCopyFilezz(string source, string destination, string extension)
 {
     List<FileInfo> files = new List<FileInfo>();
     DirectoryInfo dir = new DirectoryInfo(source);
     long maxbytes = 0;
     FileInfo[] folder = dir.GetFiles(extension, SearchOption.TopDirectoryOnly);
     foreach (FileInfo file in folder)
     {
         if ((file.Attributes & FileAttributes.Directory) != 0) continue;
         files.Add(file);
         maxbytes += file.Length;
     }
     long bytes = 0;
     Directory.CreateDirectory(destination);
     foreach (FileInfo file in files)
     {
         try
         {
             this.BeginInvoke(OnChange, new object[] { new UIProgress(file.Name, bytes, maxbytes) });
             File.Copy(file.FullName, destination + file.Name, true);
         }
         catch (Exception ex)
         {
             UIError err = new UIError(ex, file.FullName);
             this.Invoke(OnError, new object[] { err });
             if (err.result == DialogResult.Cancel) break;
         }
         bytes += file.Length;
     }
 }
예제 #8
0
파일: Form1.cs 프로젝트: dant0n/CopyPaste
        private void copyCopyDirectoryzz(string source, string destination, bool copySubDirs)
        {
            DirectoryInfo dir = new DirectoryInfo(source);
            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException("Нет же такой папки: " + source);
            }
            if ((dir.Attributes & FileAttributes.Hidden) == 0)
            {
                List<FileInfo> files = new List<FileInfo>();
                Directory.CreateDirectory(destination);
                DirectoryInfo[] dirs = dir.GetDirectories();
                FileInfo[] filesInFolder = dir.GetFiles();
                long maxbytes = 0;
                foreach (FileInfo file in filesInFolder)
                {
                    if ((file.Attributes & FileAttributes.Directory) != 0) continue;
                    files.Add(file);
                    maxbytes += file.Length;
                }

                long bytes = 0;
                foreach (FileInfo file in files)
                {
                    try
                    {
                        this.BeginInvoke(OnChange, new object[] { new UIProgress(file.Name, bytes, maxbytes) });
                        string temppath = Path.Combine(destination, file.Name);
                        file.CopyTo(temppath, true);
                    }
                    catch (Exception ex)
                    {
                        UIError err = new UIError(ex, file.FullName);
                        this.Invoke(OnError, new object[] { err });
                        if (err.result == DialogResult.Cancel) break;
                    }
                    bytes += file.Length;
                }

                if (copySubDirs)
                {
                    foreach (DirectoryInfo subdir in dirs)
                    {
                        string temppath = Path.Combine(destination, subdir.Name);
                        copyCopyDirectoryzz(subdir.FullName, temppath, copySubDirs);
                    }
                }
            }
        }
예제 #9
0
파일: Form1.cs 프로젝트: dant0n/CopyPaste
 private void Copier_Error(UIError err)
 {
     string msg = string.Format("Ошибка в копировании файла {0}\n{1}\nЖми ОК для продолжения", err.path, err.msg);
     err.result = MessageBox.Show(msg, "ОШИБОЧКА", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
 }