Exemplo n.º 1
0
        private bool moveFile(string pDestination, ArrayList pDestinationFiles, FileStream pSourceFile,
                              string pSourceName, bool pOverwriteExisting, bool pCompressOutput,
                              bool hasMultipleExtensions)
        {
            int readSize = 0;

            byte[] data         = new byte[4096];
            string pZipFilePath = String.Empty;

            string filePath;
            string path;
            string destinationPath = String.Empty;
            string searchPattern;

            bool isSuccess = false;

            try
            {
                foreach (AuditingUtil.ChecksumStruct cs in pDestinationFiles)
                {
                    filePath = buildFilePath(cs.game, Path.ChangeExtension(cs.rom, Path.GetExtension(pSourceFile.Name)));
                    path     = pDestination + filePath.Substring(0, filePath.LastIndexOf(Path.DirectorySeparatorChar));

                    if (hasMultipleExtensions)
                    {
                        searchPattern = Path.GetFileNameWithoutExtension(cs.rom) + ".*";
                    }
                    else
                    {
                        searchPattern = Path.GetFileName(cs.rom);
                    }

                    if (pCompressOutput)
                    {
                        pZipFilePath    = pDestination + cs.game + ".zip";
                        destinationPath = Path.ChangeExtension(cs.rom, Path.GetExtension(pSourceFile.Name));
                        CompressionUtil.AddFileToZipFile(pZipFilePath, pSourceName, destinationPath);
                    }
                    else
                    {
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        if (pOverwriteExisting || Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories).Length == 0)
                        {
                            File.Delete(pDestination + filePath);
                            FileStream streamWriter = File.Create(pDestination + filePath);
                            pSourceFile.Seek(0, SeekOrigin.Begin);

                            while (true)
                            {
                                readSize = pSourceFile.Read(data, 0, data.Length);
                                if (readSize > 0)
                                {
                                    streamWriter.Write(data, 0, readSize);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            streamWriter.Close();
                            streamWriter.Dispose();
                        }
                    }
                } // foreach (AuditingUtil.ChecksumStruct cs in pDestinationFiles)


                isSuccess = true;
            }
            catch (Exception exception)
            {
                this.progressStruct.Clear();
                this.progressStruct.FileName     = pSourceName;
                this.progressStruct.ErrorMessage = "Error rebuilding <" + pSourceName + "> to destination: " + exception.Message + Environment.NewLine;
                ReportProgress(Constants.IgnoreProgress, this.progressStruct);
                isSuccess = false;
            }

            return(isSuccess);
        }