コード例 #1
0
ファイル: ProjectManager.cs プロジェクト: NekoProject/NekoKun
        public static string CreateProject(string dir, ArchiveFile template)
        {
            System.IO.Directory.CreateDirectory(dir);
            template.Extract(dir);

            return System.IO.Path.Combine(dir, "Game.nkproj");
        }
コード例 #2
0
ファイル: DSTankUnpacker.cs プロジェクト: darkstar/gus
        void ReadFileSet(ArchiveFile af, Stream strm)
        {
            BinaryReader rd = new BinaryReader(strm);

            strm.Seek(af.Header.FileSetOffset, SeekOrigin.Begin);

            af.FileSet = new FileSet();
            af.FileSet.Count = rd.ReadUInt32();
            af.FileSet.Offsets = new uint[af.FileSet.Count];
            af.FileSet.Entries = new FileSetEntry[af.FileSet.Count];

            for (int i = 0; i < af.FileSet.Count; i++)
            {
                af.FileSet.Offsets[i] = rd.ReadUInt32();
            }

            for (int i = 0; i < af.FileSet.Count; i++)
            {
                short strlen;
                byte[] strbuf;

                strm.Seek(af.Header.FileSetOffset + af.FileSet.Offsets[i], SeekOrigin.Begin);

                af.FileSet.Entries[i] = new FileSetEntry();
                af.FileSet.Entries[i].ParentOffset = rd.ReadUInt32();
                af.FileSet.Entries[i].Size = rd.ReadUInt32();
                af.FileSet.Entries[i].Offset = rd.ReadUInt32();
                af.FileSet.Entries[i].CRC = rd.ReadUInt32();
                af.FileSet.Entries[i].FileTime = DateTime.FromFileTime(rd.ReadInt64());
                af.FileSet.Entries[i].Format = rd.ReadInt16();
                af.FileSet.Entries[i].Flags = rd.ReadInt16();

                strlen = rd.ReadInt16();
                strlen++; // add 0-byte at the end
                while ((2 + strlen) % 4 != 0) // pad to dword size
                    strlen++;
                strbuf = new byte[strlen];
                rd.Read(strbuf, 0, strlen);

                string name = Encoding.ASCII.GetString(strbuf);
                if (name.IndexOf('\0') >= 0)
                    name = name.Substring(0, name.IndexOf('\0'));

                af.FileSet.Entries[i].Name = name;

                if (af.FileSet.Entries[i].Format != 0)
                {
                    // compressed resource; read compression header
                    af.FileSet.Entries[i].CompressedSize = rd.ReadUInt32();
                    af.FileSet.Entries[i].ChunkSize = rd.ReadUInt32();
                    af.FileSet.Entries[i].NumChunks = (uint)Math.Ceiling((double)af.FileSet.Entries[i].Size / (double)af.FileSet.Entries[i].ChunkSize);
                    af.FileSet.Entries[i].ChunkHeaders = new ChunkHeader[af.FileSet.Entries[i].NumChunks];
                    for (int j = 0; j < af.FileSet.Entries[i].NumChunks; j++)
                    {
                        af.FileSet.Entries[i].ChunkHeaders[j] = new ChunkHeader();
                        af.FileSet.Entries[i].ChunkHeaders[j].UncompressedSize = rd.ReadUInt32();
                        af.FileSet.Entries[i].ChunkHeaders[j].CompressedSize = rd.ReadUInt32();
                        af.FileSet.Entries[i].ChunkHeaders[j].ExtraBytes = rd.ReadUInt32();
                        af.FileSet.Entries[i].ChunkHeaders[j].Offset = rd.ReadUInt32();
                    }
                }

                // add to lookup table
                af.FileOffsets.Add(af.FileSet.Offsets[i], af.FileSet.Entries[i]);
            }
        }
コード例 #3
0
ファイル: DSTankUnpacker.cs プロジェクト: darkstar/gus
        void ReadDirSet(ArchiveFile af, Stream strm)
        {
            BinaryReader rd = new BinaryReader(strm);

            strm.Seek(af.Header.DirSetOffset, SeekOrigin.Begin);
            af.DirectorySet = new DirSet();
            af.DirectorySet.Count = rd.ReadUInt32();
            af.DirectorySet.Offsets = new uint[af.DirectorySet.Count];
            af.DirectorySet.Entries = new DirSetEntry[af.DirectorySet.Count];

            // read the offsets
            for (uint i = 0; i < af.DirectorySet.Count; i++)
            {
                af.DirectorySet.Offsets[i] = rd.ReadUInt32();
            }
            for (uint i = 0; i < af.DirectorySet.Count; i++)
            {
                short strlen;
                byte[] strbuf;

                strm.Seek(af.Header.DirSetOffset + af.DirectorySet.Offsets[i], SeekOrigin.Begin);
                af.DirectorySet.Entries[i] = new DirSetEntry();
                af.DirectorySet.Entries[i].ParentOffset = rd.ReadUInt32();
                af.DirectorySet.Entries[i].ChildCount = rd.ReadUInt32();
                af.DirectorySet.Entries[i].FileTime = DateTime.FromFileTime(rd.ReadInt64());
                strlen = rd.ReadInt16();
                strlen++; // add 0-byte at the end
                while ((2 + strlen) % 4 != 0) // pad to dword size
                    strlen++;
                strbuf = new byte[strlen];
                rd.Read(strbuf, 0, strlen);

                string name = Encoding.ASCII.GetString(strbuf);
                if (name.IndexOf('\0') >= 0)
                    name = name.Substring(0, name.IndexOf('\0'));
                af.DirectorySet.Entries[i].Name = name;
                af.DirectorySet.Entries[i].ChildOffsets = new uint[af.DirectorySet.Entries[i].ChildCount];
                for (int j = 0; j < af.DirectorySet.Entries[i].ChildCount; j++)
                {
                    af.DirectorySet.Entries[i].ChildOffsets[j] = rd.ReadUInt32();
                }

                // add to lookup table
                af.DirOffsets.Add(af.DirectorySet.Offsets[i], af.DirectorySet.Entries[i]);
            }
            af.DirectorySet.EndOffset = (uint)strm.Position;
        }
コード例 #4
0
ファイル: DSTankUnpacker.cs プロジェクト: darkstar/gus
        private ArchiveFile ReadDirectory(Stream strm)
        {
            ArchiveFile af = new ArchiveFile();

            af.Header = ReadGlobalHeader(strm);
            ReadDirSet(af, strm);
            ReadFileSet(af, strm);

            return af;
        }
コード例 #5
0
ファイル: DSTankUnpacker.cs プロジェクト: darkstar/gus
        private string GetRelPath(ArchiveFile af, FileSetEntry fse)
        {
            string res = fse.Name;
            uint ParentOffset = fse.ParentOffset;

            while (ParentOffset != 0)
            {
                DirSetEntry dse = af.DirOffsets[ParentOffset];
                if (dse.ParentOffset == 0)
                    break;
                res = String.Format("{0}/{1}", dse.Name, res);
                ParentOffset = dse.ParentOffset;
            }

            return res;
        }
コード例 #6
0
ファイル: UpdateWindow.xaml.cs プロジェクト: Satroki/EVETools
        private async Task<MemoryStream> getExcel()
        {
            try
            {
                var url = Settings.Default.DbUrl;
                var path = Path.Combine(Environment.CurrentDirectory, "temp");
                var file = Path.GetFileName(url);
                var filename = Path.Combine(path, file);
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                var wc = new WebClient();

                log("下载...");
                wc.DownloadProgressChanged += (s, e) => Percent = e.ProgressPercentage;

                await wc.DownloadFileTaskAsync(new Uri(url), filename);
                logLine("完成");
                log("解压...");
                var ms = new MemoryStream();
                using (var zip = new ArchiveFile(filename, "7z-x86.dll"))
                {
                    foreach (var item in zip.Entries)
                        if (item.FileName.EndsWith(".xls"))
                        { item.Extract(ms); break; }
                }
                return ms;
            }
            catch (Exception ex)
            {
                logLine(ex.Message);
                return null;
            }
        }
コード例 #7
0
ファイル: ArchiveFolder.cs プロジェクト: Hakerok/File_Manager
        public override void AbstractOpen()
        {
            DirectoriesList.Clear();
            FilesList.Clear();

            var arc = ZipFile.Open(AbstractPath, ZipArchiveMode.Update);
           
                var existingFolders = new List<string>();

                foreach (var item in arc.Entries)
                {
                    if (item.FullName.LastIndexOf(@"/", System.StringComparison.Ordinal) == item.FullName.Length - 1)
                    {
                        if (InnerPath == "")
                        {
                            if (
                                existingFolders.Contains(item.FullName.Substring(0,
                                    item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1)) ||
                                item.FullName.Substring(0,
                                    item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1) == "") continue;
                            var newFolder = new ArchiveFolder(AbstractPath, item.FullName.Substring(0, item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1));
                            DirectoriesList.Add(newFolder);
                            existingFolders.Add(item.FullName.Substring(0, item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1));
                        }
                        else
                        {
                            if (item.FullName.IndexOf(InnerPath, System.StringComparison.Ordinal) >= 0)
                            {
                                var inPath = item.FullName.Replace(InnerPath, "");
                                if (!existingFolders.Contains(inPath.Substring(0, inPath.IndexOf(@"/", System.StringComparison.Ordinal) + 1)) &&
                                    inPath.Substring(0, inPath.IndexOf(@"/", System.StringComparison.Ordinal) + 1) != "")
                                {
                                    var newFolder = new ArchiveFolder(AbstractPath, item.FullName);
                                    DirectoriesList.Add(newFolder);
                                    existingFolders.Add(inPath.Substring(0, inPath.IndexOf(@"/", System.StringComparison.Ordinal) + 1));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (InnerPath == "")
                        {
                            if (item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) < 0)
                            {
                                var newFile = new ArchiveFile(item.FullName, item);
                                FilesList.Add(newFile);
                            }
                        }
                        else
                        {
                            if (item.FullName.IndexOf(InnerPath, System.StringComparison.Ordinal) >= 0)
                            {
                                var inPath = item.FullName.Replace(InnerPath, "");
                                if (inPath.IndexOf(@"/", System.StringComparison.Ordinal) < 0)
                                {
                                    var newFile = new ArchiveFile(item.FullName, item);
                                    FilesList.Add(newFile);
                                }
                            }
                        }
                    }
                }

            }
コード例 #8
0
ファイル: ArchiveFolder.cs プロジェクト: Hakerok/File_Manager
 public override AbstractFile AbstractCreateFile(string fileName)
 {
     using (var arc = ZipFile.Open(AbstractPath, ZipArchiveMode.Update))
     {
         var newEntry = arc.CreateEntry(InnerPath + fileName);
         var newFile = new ArchiveFile(newEntry.FullName, newEntry);
         return newFile;
     }
 }
コード例 #9
0
        public CreateProjectWizard()
        {
            InitializeComponent();

            string[] filelist = StorageManager.GetVirtualDirectoryFiles("Templates", "*.nkar", System.IO.SearchOption.AllDirectories);

            this.templateList.LargeImageList = new ImageList();
            this.templateList.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            this.templateList.LargeImageList.ImageSize = new Size(48, 48);
            this.templateList.SmallImageList = new ImageList();
            this.templateList.SmallImageList.ColorDepth = ColorDepth.Depth32Bit;
            this.templateList.SmallImageList.ImageSize = new Size(16, 16);
            this.templateList.Columns.Add("名称");
            this.templateList.Columns.Add("版本");
            this.templateList.Columns.Add("语言");
            this.templateList.Columns.Add("备注");
            this.templateList.View = View.Details;
            this.templateList.MultiSelect = false;
            this.templateList.FullRowSelect = true;
            this.templateList.HideSelection = false;
            this.templateList.Sorting = SortOrder.Ascending;

            foreach (string filename in filelist)
            {
                try
                {
                    ArchiveFile file = new ArchiveFile(filename);
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.LoadXml(file.Manifest);

                    XmlNode root = xmldoc["NekoKunProjectTemplate"];
                    if (new Version(root.Attributes["Version"].Value) > new Version(((System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false)[0] as System.Reflection.AssemblyFileVersionAttribute).Version)))
                        throw new ArgumentException("The project template file was created in a newer version of NekoKun which is not supported by this version of NekoKun.");

                    ListViewItem lvi = new ListViewItem();
                    lvi.Tag = file;
                    lvi.Text = root["Title"].InnerText;
                    lvi.SubItems.Add(root["Version"] != null ? root["Version"].InnerText : "");
                    lvi.SubItems.Add(root["Language"] != null ? root["Language"].InnerText : "");
                    lvi.SubItems.Add(root["Description"] != null ? root["Description"].InnerText : "");
                    lvi.ToolTipText = root["Description"] != null ? root["Description"].InnerText : "";
                    if (root["Icon"] != null)
                    {
                        Image image = NekoKun.Core.DrawingHelper.DecodeBase64Image(root["Icon"].InnerText);

                        this.templateList.LargeImageList.Images.Add(filename, image);
                        this.templateList.SmallImageList.Images.Add(filename, image);
                        lvi.ImageKey = filename;
                    }

                    this.templateList.Items.Add(lvi);
                }
                catch { }
            }

            if (this.templateList.Items.Count >= 1)
                this.templateList.Items[0].Selected = true;

            this.templateList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);

            FillFields();
            this.fieldName.TextChanged += new EventHandler(fieldName_TextChanged);
            this.browseFolderButton.Click += new EventHandler(browseFolderButton_Click);
            UpdateAccept();

            this.templateList.ItemSelectionChanged += delegate { UpdateAccept(); };
            this.fieldLocation.TextChanged += delegate { UpdateAccept(); };
            this.fieldName.TextChanged += delegate { UpdateAccept(); };

            this.accpetButton.Click += new EventHandler(accpetButton_Click);
        }
コード例 #10
0
 private void AddToListOfFiles(ArchiveFile extractFile)
 {
     if (!_fileNames.Any(file => file.Equals(extractFile.Name)))
     {
         _fileNames.Add(extractFile.Name);
     }
 }
コード例 #11
0
 private bool ShouldIgnoreFile(ArchiveFile extractFile)
 {
     var rootFolder = GetFileRootFolder(extractFile.Name);
     return _subDirectoryToIgnore.Any(dir => dir.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase));
 }
コード例 #12
0
        private IntPtr OutputFileOpen(NativeMethods.FdiNotification fdin)
        {
            var extractFile = new ArchiveFile { Name = GetFileName(fdin) };
            if (ShouldIgnoreFile(extractFile))
            {
                //ignore this file.
                return IntPtr.Zero;
            }
            var stream = new MemoryStream();
            GCHandle gch = GCHandle.Alloc(stream);
            extractFile.Handle = (IntPtr)gch;

            AddToListOfFiles(extractFile);

            //return IntPtr.Zero so that the iteration will keep on going
            return IntPtr.Zero;
        }
コード例 #13
0
 private void ExtractFile(string fileName)
 {
     _currentFileToDecompress = new ArchiveFile { Name = fileName };
     FdiCopy();
     CreateAllRelevantDirectories(fileName);
     if (_currentFileToDecompress.Data != null)
     {
         File.WriteAllBytes(Path.Combine(_extractionFolderPath, _currentFileToDecompress.Name), _currentFileToDecompress.Data);
     }
 }