Пример #1
0
 private string openZipEntry(
     string fileName,
     ZipLib.Zip.ZipFile zip, ZipLib.Zip.ZipEntry entry,
     string source)
 {
     using (Stream s = zip.GetInputStream(entry))
     {
         byte[] data = new byte[entry.Size];
         s.Read(data, 0, data.Length);
         using (MemoryStream ms = new MemoryStream(data))
         {
             if (intCheckCanOpenFileName(entry.Name))
             {
                 openStream(ms, Path.GetExtension(entry.Name).ToUpper(), source, true);
             }
             else
             {
                 Locator.Resolve <IUserMessage>().Error(
                     "Can't open {0}\\{1}!\n\nFile not supported!",
                     fileName,
                     entry.Name);
                 return(string.Empty);
             }
             return(string.Format("{0}/{1}", Path.GetFileName(fileName), entry.Name));
         }
     }
 }
Пример #2
0
        private static long GetImageLength(string fileName)
        {
            var folderName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // override
            var romsFolderName = Path.Combine(folderName, "roms");

            if (Directory.Exists(romsFolderName))
            {
                var romsFileName = Path.Combine(romsFolderName, fileName);
                if (File.Exists(romsFileName))
                {
                    return(new FileInfo(romsFileName).Length);
                }
            }

            var pakFileName = Path.Combine(folderName, "ROMS.PAK");

            using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(pakFileName))
            {
                foreach (ZipLib.Zip.ZipEntry entry in zip)
                {
                    if (entry.IsFile &&
                        entry.CanDecompress &&
                        string.Compare(entry.Name, fileName, true) == 0)
                    {
                        return(entry.Size);
                    }
                }
            }
            throw new FileNotFoundException(string.Format("ROM file not found: {0}", fileName));
        }
Пример #3
0
 public bool CheckCanOpenFileName(string fileName)
 {
     if (Path.GetExtension(fileName).ToUpper() != ".ZIP")
     {
         return intCheckCanOpenFileName(fileName);
     }
     else
     {
         using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(fileName))
             foreach (ZipLib.Zip.ZipEntry entry in zip)
                 if (entry.IsFile && entry.CanDecompress && intCheckCanOpenFileName(entry.Name))
                     return true;
     }
     return false;
 }
Пример #4
0
 public bool CheckCanOpenFileName(string fileName)
 {
     if (Path.GetExtension(fileName).ToUpper() != ".ZIP")
     {
         return(intCheckCanOpenFileName(fileName));
     }
     else
     {
         using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(fileName))
             foreach (ZipLib.Zip.ZipEntry entry in zip)
             {
                 if (entry.IsFile && entry.CanDecompress && intCheckCanOpenFileName(entry.Name))
                 {
                     return(true);
                 }
             }
     }
     return(false);
 }
Пример #5
0
        private static Stream GetImageStream(string fileName)
        {
            var folderName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            // override
            var romsFolderName = Path.Combine(folderName, "roms");

            if (Directory.Exists(romsFolderName))
            {
                var romsFileName = Path.Combine(romsFolderName, fileName);
                if (File.Exists(romsFileName))
                {
                    using (var fs = new FileStream(romsFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        return(CreateStream(fs, fs.Length));
                    }
                }
            }

            var pakFileName = Path.Combine(folderName, "ROMS.PAK");

            using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(pakFileName))
            {
                foreach (ZipLib.Zip.ZipEntry entry in zip)
                {
                    if (entry.IsFile &&
                        entry.CanDecompress &&
                        string.Compare(entry.Name, fileName, true) == 0)
                    {
                        using (var s = zip.GetInputStream(entry))
                        {
                            return(CreateStream(s, entry.Size));
                        }
                    }
                }
            }
            throw new FileNotFoundException(
                      string.Format(
                          "ROM file not found: {0}",
                          fileName));
        }
Пример #6
0
 public string OpenFileStream(string fileName, Stream fileStream)
 {
     string ext = Path.GetExtension(fileName).ToUpper();
     if (ext != ".ZIP")
     {
         openStream(fileStream, ext, string.Empty, true);
         return Path.GetFileName(fileName);
     }
     else
     {
         List<ZipLib.Zip.ZipEntry> list = new List<ZipLib.Zip.ZipEntry>();
         using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(fileStream))
         {
             zip.IsStreamOwner = false;
             foreach (ZipLib.Zip.ZipEntry entry in zip)
             {
                 if (entry.IsFile && entry.CanDecompress &&
                    Path.GetExtension(entry.Name).ToUpper() != ".ZIP" &&
                    CheckCanOpenFileName(entry.Name))
                 {
                     //return openZipEntry(fileName, zip, entry);
                     list.Add(entry);
                 }
             }
             ZipLib.Zip.ZipEntry selEntry = null;
             if (list.Count == 1)
             {
                 selEntry = list[0];
             }
             else if (list.Count > 1)
             {
                 selEntry = (ZipLib.Zip.ZipEntry)DialogProvider.ObjectSelector(
                     list.ToArray(),
                     Path.GetFileName(fileName));
                 if (selEntry == null)
                     return string.Empty;
             }
             if (selEntry != null)
             {
                 string result = openZipEntry(fileName, zip, selEntry, string.Empty);
                 if (result != string.Empty)
                 {
                     return result;
                 }
             }
         }
     }
     DialogProvider.Show(
         string.Format("Can't open {0}!\n\nSupported file not found!", fileName),
         "Error",
         DlgButtonSet.OK,
         DlgIcon.Error);
     return string.Empty;
 }
Пример #7
0
        private void loadMachines()
        {
            string folderName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string fileName = Path.Combine(folderName, csMachinesPakFileName);
            try
            {
                if (!File.Exists(fileName))
                    return;
                using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(fileName))
                    foreach (ZipLib.Zip.ZipEntry entry in zip)
                        if (entry.IsFile && entry.CanDecompress && Path.GetExtension(entry.Name).ToUpper() == ".VMZ")
                        {
                            try
                            {
                                var xml = new XmlDocument();
                                using (Stream s = zip.GetInputStream(entry))
                                {
                                    xml.Load(s);
                                }
                                var vmNode = xml.SelectSingleNode("/VirtualMachine");
                                if (vmNode == null)
                                {
                                    LogAgent.Warn(
                                        "Invalid machine configuration file: {0}\\{1}",
                                        csMachinesPakFileName,
                                        entry.Name);
                                    continue;
                                }
                                string name = Path.GetFileNameWithoutExtension(entry.Name);
                                if (vmNode.Attributes["name"] != null)
                                    name = vmNode.Attributes["name"].InnerText;

                                var item = ctxMenuWizard.Items.Add(name);
                                item.Tag = xml;
                                item.Click += new EventHandler(ctxMenuWizardItem_Click);
                            }
                            catch (Exception ex)
                            {
                                LogAgent.Error(ex);
                            }
                        }
            }
            catch (Exception ex)
            {
                LogAgent.Error(ex);
            }
        }
Пример #8
0
        public string OpenFileName(string fileName, bool wp)
        {
            string ext = Path.GetExtension(fileName).ToUpper();

            if (ext != ".ZIP")
            {
                using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    openStream(stream, ext, fileName, wp);
                return(Path.GetFileName(fileName));
            }
            else
            {
                List <ZipLib.Zip.ZipEntry> list = new List <ZipLib.Zip.ZipEntry>();
                using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(fileName))
                {
                    foreach (ZipLib.Zip.ZipEntry entry in zip)
                    {
                        if (entry.IsFile && entry.CanDecompress &&
                            Path.GetExtension(entry.Name).ToUpper() != ".ZIP" &&
                            CheckCanOpenFileName(entry.Name))
                        {
                            //return openZipEntry(fileName, zip, entry);
                            list.Add(entry);
                        }
                    }
                    ZipLib.Zip.ZipEntry selEntry = null;
                    if (list.Count == 1)
                    {
                        selEntry = list[0];
                    }
                    else if (list.Count > 1)
                    {
                        var service = Locator.Resolve <IUserQuery>();
                        if (service != null)
                        {
                            selEntry = (ZipLib.Zip.ZipEntry)service.ObjectSelector(
                                list.ToArray(),
                                Path.GetFileName(fileName));
                        }
                        else
                        {
                            selEntry = list.Count > 0 ? list[0] : null;
                        }
                        if (selEntry == null)
                        {
                            return(string.Empty);
                        }
                    }
                    if (selEntry != null)
                    {
                        var result = openZipEntry(fileName, zip, selEntry, fileName);
                        if (!string.IsNullOrEmpty(result))
                        {
                            return(result);
                        }
                    }
                }
            }
            Locator.Resolve <IUserMessage>().Error(
                "Can't open {0}!\n\nSupported file not found!",
                fileName);
            return(string.Empty);
        }
Пример #9
0
        public static Stream GetRomFileStream(string fileName)
        {
            string folderName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            // override
            string romsFolderName = Path.Combine(folderName, "roms");
            if (Directory.Exists(romsFolderName))
            {
                string romsFileName = Path.Combine(romsFolderName, fileName);
                if (File.Exists(romsFileName))
                    using (FileStream fs = new FileStream(romsFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        byte[] fileData = new byte[fs.Length];
                        fs.Read(fileData, 0, fileData.Length);
                        return new MemoryStream(fileData);
                    }
            }

            string pakFileName = Path.Combine(folderName, "Roms.PAK");

            using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(pakFileName))
                foreach (ZipLib.Zip.ZipEntry entry in zip)
                    if (entry.IsFile &&
                        entry.CanDecompress &&
                        string.Compare(entry.Name, fileName, true) == 0)
                    {
                        byte[] fileData = new byte[entry.Size];
                        using (Stream s = zip.GetInputStream(entry))
                            s.Read(fileData, 0, fileData.Length);
                        return new MemoryStream(fileData);
                    }
            throw new FileNotFoundException(string.Format("ROM file not found: {0}", fileName));
        }
Пример #10
0
        public static long GetRomFileLength(string fileName)
        {
            string folderName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            // override
            string romsFolderName = Path.Combine(folderName, "roms");
            if (Directory.Exists(romsFolderName))
            {
                string romsFileName = Path.Combine(romsFolderName, fileName);
                if (File.Exists(romsFileName))
                    return new FileInfo(romsFileName).Length;
            }

            string pakFileName = Path.Combine(folderName, "Roms.PAK");

            using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(pakFileName))
                foreach (ZipLib.Zip.ZipEntry entry in zip)
                    if (entry.IsFile &&
                        entry.CanDecompress &&
                        string.Compare(entry.Name, fileName, true) == 0)
                    {
                        return entry.Size;
                    }
            throw new FileNotFoundException(string.Format("ROM file not found: {0}", fileName));
        }