Beispiel #1
0
 private static void SetProgress(FirmFinder owner, Progress form, int value, string text = "")
 {
     owner.Invoke(new Action(() =>
     {
         form.SetProgress(value, text);
     }));
 }
Beispiel #2
0
        private void CopyItPlease(Progress progress, string romname, string filename, string packagename)
        {
            try
            {
                string dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\HiSuite\ROM\" + romname + @"\full\" + packagename;

                if (File.Exists(dir))
                {
                    long victimlen = new FileInfo(dir).Length, mainfilelen = new FileInfo(filename).Length;
                    if (victimlen != mainfilelen)
                    {
                        File.Delete(dir);
                    }
                    else
                    {
                        return;
                    }
                }
                string Directoryname = Path.GetDirectoryName(dir);
                if (!Directory.Exists(Directoryname))
                {
                    Directory.CreateDirectory(Directoryname);
                }
                using (FileStream stream = File.OpenRead(filename))
                {
                    long totallen = stream.Length;
                    using (FileStream write = File.OpenWrite(dir))
                    {
                        long   writtenlen = 0;
                        int    readdata   = 4096;
                        byte[] data       = new byte[readdata];
                        while ((readdata = stream.Read(data, 0, data.Length)) > 0)
                        {
                            write.Write(data, 0, readdata);
                            writtenlen += readdata;
                            int percentage = (int)((writtenlen * 100) / totallen);
                            if ((percentage % 5) == 0)
                            {
                                this.Invoke(new Action(() =>
                                {
                                    progress.SetProgress(percentage);
                                }));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (!e.Message.StartsWith("Thread was being"))
                {
                    MessageBox.Show(e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }