Esempio n. 1
0
 private void CleanupTempFiles(string aPath, string aPrefix, Flash.IConsole aConsole)
 {
     try {
         aConsole.ProgressOpen(100);
         string[] fileList = Directory.GetFiles(aPath, (aPrefix + "*"));
         aConsole.ProgressSetValue(25);
         string[] dirList = Directory.GetDirectories(aPath, (aPrefix + "*"));
         aConsole.ProgressSetValue(50);
         foreach (string file in fileList)
         {
             File.Delete(file);
         }
         aConsole.ProgressSetValue(75);
         foreach (string dir in dirList)
         {
             Directory.Delete(dir, true); // true is for delete recursively
         }
         aConsole.ProgressSetValue(90);
     }
     catch (Exception e) {
         UserLog.WriteLine("Error: " + e.Message);
     }
     aConsole.Write("Complete");
     aConsole.ProgressClose();
 }
Esempio n. 2
0
        private string GetRomFromZip(string aZipFile, string aVariant, Flash.IConsole aConsole, out string aUnzippedDirectory)
        {
            // unzip downloaded file to temp directory
            aConsole.ProgressOpen(100);
            aUnzippedDirectory = Path.Combine(iHelper.DataPath.FullName, Path.GetFileNameWithoutExtension(aZipFile));
            aConsole.ProgressSetValue(10);
            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            aConsole.ProgressSetValue(20);
            fz.ExtractZip(aZipFile, aUnzippedDirectory, ""); // "" is for file filter
            aConsole.ProgressSetValue(60);

            // Only one main folder per zip file (i.e. Reprog_Date/SXXXXXXXX)
            string[] mainDirs = Directory.GetDirectories(aUnzippedDirectory, "*", SearchOption.TopDirectoryOnly);
            if (mainDirs.Length != 1)
            {
                throw new GetRomFromZipFailed("File structure is invalid in " + aUnzippedDirectory);
            }
            aConsole.ProgressSetValue(70);
            // Directory below main directory must be the aVariant directory (i.e. Reprog_Date/SXXXXXXXX/AkuarateDsMk1)
            string[] dirs = Directory.GetDirectories(mainDirs[0], aVariant, SearchOption.TopDirectoryOnly);
            aConsole.ProgressSetValue(80);
            if (dirs.Length <= 0)
            {
                throw new GetRomFromZipFailed("Could not find " + aVariant + " directory in " + mainDirs[0]);
            }
            else if (dirs.Length > 1)
            {
                throw new GetRomFromZipFailed("Found multiple " + aVariant + " directories in " + mainDirs[0]);
            }
            // Only one collection file in the aVariant directory (i.e. Reprog_Date/SXXXXXXXX/AkuarateDsMk1/bin/CollectionAkurateDs.xml)
            string[] files = Directory.GetFiles(dirs[0], "Collection*.xml", SearchOption.AllDirectories);
            aConsole.ProgressSetValue(90);
            if (files.Length <= 0)
            {
                throw new GetRomFromZipFailed("Could not find required Collection file for " + aVariant + " in " + dirs[0]);
            }
            else if (files.Length > 1)
            {
                throw new GetRomFromZipFailed("Found multiple Collection files for " + aVariant + " in " + dirs[0]);
            }

            aConsole.Write("Complete");
            aConsole.ProgressClose();
            UserLog.Write(" [ROM file selected: " + files[0] + "]");
            return(files[0]);
        }
Esempio n. 3
0
        private void DownloadFile(string aUrl, string aFilename, Flash.IConsole aConsole)
        {
            int             bytesdone = 0;
            Stream          rStream   = null;
            Stream          lStream   = null;
            HttpWebResponse response  = null;
            int             fileSize  = 0;

            try {
                aConsole.ProgressOpen(fileSize);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(aUrl);
                request.Credentials       = CredentialCache.DefaultCredentials;
                request.Proxy.Credentials = CredentialCache.DefaultCredentials;

                if (request != null)
                {
                    response = (HttpWebResponse)request.GetResponse();
                }
                if (response != null)
                {
                    fileSize = (int)response.ContentLength;
                    rStream  = response.GetResponseStream();
                    lStream  = File.Create(aFilename);
                    byte[] buffer = new byte[2048]; // read in 2K chunks
                    int    bytesRead;
                    int    currPercent = 0;
                    int    lastPercent = 0;
                    aConsole.ProgressOpen(fileSize); // open progress console with max value
                    do
                    {
                        bytesRead = rStream.Read(buffer, 0, buffer.Length);
                        lStream.Write(buffer, 0, bytesRead);
                        bytesdone  += bytesRead;
                        currPercent = (bytesdone * 100) / fileSize;
                        if ((currPercent != lastPercent) && (currPercent % 5 == 0))
                        {
                            // mono/win forms can't handle lots of events - cut down to 5% steps
                            aConsole.ProgressSetValue(bytesdone);
                            lastPercent = currPercent;
                        }
                    } while (bytesRead > 0);
                }
            }
            finally {
                if (response != null)
                {
                    response.Close();
                }
                if (rStream != null)
                {
                    rStream.Close();
                }
                if (lStream != null)
                {
                    lStream.Close();
                }
            }
            aConsole.Write("Complete");
            aConsole.ProgressClose();
            UserLog.Write(" [Downloaded File: " + aUrl + " --> " + aFilename + " (" + bytesdone + " bytes)]");
        }