private void CheckPreviousVersion(FileMap script) { using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024)) { stream.WriteLine(string.Format("bash {0}", script.RemotePath)); var output = stream.Expect(Settings.InstallationStopPattern); if (output.Contains(Settings.InstallationSuccessPattern)) { InstallationComponents = new InstallationComponentsModel { MailServer = !string.IsNullOrEmpty(GetTerminalParam(output, "MAIL_SERVER_ID")), DocumentServer = !string.IsNullOrEmpty(GetTerminalParam(output, "DOCUMENT_SERVER_ID")), CommunityServer = !string.IsNullOrEmpty(GetTerminalParam(output, "COMMUNITY_SERVER_ID")) }; InstallationProgress.ProgressText += output; } if (output.Contains(Settings.InstallationErrorPattern)) { throw new Exception(output); } } CacheHelper.SetInstalledComponents(UserId, InstallationComponents.IsEmpty ? null : InstallationComponents); }
//Parser commands must initialize the node before returning. public static ResourceNode FromFile(ResourceNode parent, string path) { ResourceNode node = null; FileMap map = FileMap.FromFile(path, FileMapProtect.Read); try { if (Path.GetExtension(path).ToUpper().ToString() == ".MRG") { node = new MRGNode(); node.Initialize(parent, map); } else if (Path.GetExtension(path).ToUpper().ToString() == ".REL") { node = new RELNode(); node.Initialize(parent, map); } else if (Path.GetExtension(path).ToUpper().ToString() == ".DOL") { node = new DOLNode(); node.Initialize(parent, map); } else { node = FromSource(parent, new DataSource(map)); } } finally { if (node == null) { map.Dispose(); } } return(node); }
private OsInfo GetOsInfo(FileMap script) { InstallationProgress.Step = InstallationProgressStep.GetOsInfo; CacheHelper.SetInstallationProgress(UserId, InstallationProgress); using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024)) { stream.WriteLine(string.Format("sudo bash {0}", script.RemotePath)); var output = stream.Expect(Settings.InstallationStopPattern); if (output.Contains(Settings.InstallationSuccessPattern)) { InstallationProgress.ProgressText += output; } if (output.Contains(Settings.InstallationErrorPattern)) { throw new Exception(output); } } var osInfo = new OsInfo { Dist = GetTerminalParam(InstallationProgress.ProgressText, "DIST"), Ver = GetTerminalParam(InstallationProgress.ProgressText, "REV"), Type = GetTerminalParam(InstallationProgress.ProgressText, "MACH"), Kernel = GetTerminalParam(InstallationProgress.ProgressText, "KERNEL") }; return(osInfo); }
public DataSource(FileMap map, CompressionType compression) { Address = map.Address; Length = map.Length; Map = map; Compression = compression; }
private string UpdateHrefCore(string href, RelativePath fromFile) { if (href.Length == 0) { return(string.Empty); } var path = UriUtility.GetPath(href); if (path.Length == 0) { return(href); } var qf = UriUtility.GetQueryStringAndFragment(href); var rp = RelativePath.TryParse(path); if (rp == null || !rp.IsFromWorkingFolder()) { return(href); } if (!FileMap.TryGetValue(rp.UrlDecode(), out string filePath)) { return(href); } string modifiedPath; if (fromFile == null) { modifiedPath = ((RelativePath)filePath).UrlEncode(); } else { modifiedPath = ((RelativePath)filePath - fromFile).UrlEncode(); } return(modifiedPath + qf); }
private void RemoveFiles(object obj) { try { FileData root = (FileData)obj; // Folders foreach (FileData folder in root.GetFolders()) { lock (FolderMap) FolderMap.Remove(folder.Id); RemoveFiles(folder); } // Files lock (FileMap) { foreach (FileData file in root.GetFiles()) { FileMap.Remove(file.Id); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } OnFile(); }
// Files private void AddFiles(object obj) { try { FileData root = (FileData)obj; // Folders foreach (FileData folder in root.GetFolders()) { lock (FolderMap) FolderMap.Add(folder.Id, folder); AddFiles(folder); } // Files foreach (FileData file in root.GetFiles()) { // Do not verify if the file is accessible lock (FileMap) FileMap.Add(file.Id, file); } } catch (Exception ex) { Console.WriteLine(ex.Message); } OnFile(); }
public void Close() { if (Map != null) { Map.Dispose(); Map = null; } Address = null; Length = 0; Compression = CompressionType.None; }
private string RunScript(InstallationProgressStep?progressStep, FileMap runServerScript, bool useSudo, params string[] scriptParams) { if (progressStep.HasValue) { InstallationProgress.Step = progressStep.Value; CacheHelper.SetInstallationProgress(UserId, InstallationProgress); } var commandFormat = (useSudo ? "sudo " : string.Empty) + "bash {0} {1}"; using (var stream = SshClient.CreateShellStream("terminal", 300, 100, 800, 600, 1024)) { stream.WriteLine(string.Format(commandFormat, runServerScript.RemotePath, String.Join(" ", scriptParams))); var output = stream.Expect(Settings.InstallationStopPattern); if (output.Contains(Settings.InstallationErrorPattern)) { throw new Exception(output); } if (output.Contains(Settings.InstallationSuccessPattern)) { InstallationProgress.ProgressText += output; } return(output); } }
private void btnOkay_Click(object sender, EventArgs e) { Stop(); if (_initialStream == null) { using (ProgressWindow progress = new ProgressWindow(this, String.Format("{0} Converter", _type == 0 ? "Brstm" : "Wave"), "Encoding, please wait...", false)) switch (_type) { case 0: var encoding = (WaveEncoding)ddlEncoding.SelectedItem; PreviousEncoding = encoding; _audioData = RSTMConverter.Encode(_sourceStream, progress, encoding); break; case 1: _audioData = RSARWaveConverter.Encode(_sourceStream, progress); break; case 2: _audioData = RWAVConverter.Encode(_sourceStream, progress); break; } } DialogResult = DialogResult.OK; Close(); }
public async Task <IActionResult> UploadFile(string sessionKey) { FileMap fileMap = await ProgressSessionService.StreamFileToServer(HttpContext.Request, ModelState, Logger, sessionKey); fileMap.UnadjustedDisplayFilename = fileMap.FilenameForDisplay; FileMap[] existingMaps = DatabaseContext.FileMaps.Where(map => map.UnadjustedDisplayFilename == fileMap.UnadjustedDisplayFilename).ToArray(); if (existingMaps == null || existingMaps.Length > 0) { fileMap.FilenameForDisplay = AddSuffixToFilename(fileMap.FilenameForDisplay, existingMaps.Length.ToString()); } DatabaseContext.FileMaps.Add(fileMap); try { await DatabaseContext.SaveChangesAsync(); } catch (DbUpdateException) { if (DatabaseContext.FileMaps.Any(entry => entry.Id == fileMap.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction(nameof(UploadFile), new { filePath = fileMap.FilenameForDisplay })); }
// // Outer funcs // /// <summary> /// This functions asks the AAS REST repository on given location, which AasIds would be availble. /// Using the AasIds, details are retrieved for each inidivudal AAS and synchronized with the /// repository. /// Note: for the time being, the list of file items is recreated, but not synchronized /// Note: due to the nature of long-lasting actions, this is by design async! /// </summary> /// <returns>If a successfull retrieval could be made</returns> public async Task <bool> SyncronizeFromServerAsync() { // access if (true != _connector?.IsValid()) { return(false); } // try get a list of items from the connector var items = await _connector.GenerateRepositoryFromEndpointAsync(); // just re-set FileMap.Clear(); foreach (var fi in items) { if (fi != null) { FileMap.Add(fi); fi.ContainerList = this; } } // ok return(true); }
public override unsafe void Export(string outPath) { int length = 12 + (_numEntries != 0 ? _colors.Count * 4 : 4); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(length); using (FileMap map = FileMap.FromStream(stream)) { CLR0MaterialEntry *entry = (CLR0MaterialEntry *)map.Address; entry->_colorMask = _colorMask; entry->_data = 8; *((bint *)entry + 2) = _numEntries; RGBAPixel *pData = entry->Data; if (_numEntries != 0) { foreach (ARGBPixel p in _colors) { *pData++ = (RGBAPixel)p; } } else { *pData = _solidColor; } } } }
public static IEnumerable <PropertyInfo> GetPropertiesToChange(Type type, FileMap map) { return(from prop in type.GetProperties() from key in map.FieldMap where prop.Name == key.TableFieldName && key.IsIndex == false select prop); }
public virtual void Rebuild(bool force) { if (!IsDirty && !force) { return; } //Get uncompressed size int size = OnCalculateSize(force); //Create temp map FileMap uncompMap = FileMap.FromTempFile(size); //Rebuild node (uncompressed) Rebuild(uncompMap.Address, size, force); _replSrc.Map = _replUncompSrc.Map = uncompMap; //If compressed, compress resulting data. if (_compression != CompressionType.None) { //Compress node to temp file FileStream stream = new FileStream(Path.GetTempFileName(), FileMode.Open, FileAccess.ReadWrite, FileShare.None, 0x8, FileOptions.DeleteOnClose | FileOptions.SequentialScan); try { Compressor.Compact(_compression, uncompMap.Address, uncompMap.Length, stream); _replSrc = new DataSource(FileMap.FromStreamInternal(stream, FileMapProtect.Read, 0, (int)stream.Length), _compression); } catch (Exception x) { stream.Dispose(); throw x; } } }
public void TestCreate() { ElementFactory ef = new ElementFactory(); ef.AddType(new global::jabber.protocol.iq.Factory()); string g = new Guid().ToString(); FileMap<DiscoInfo> fm = new FileMap<DiscoInfo>("test.xml", ef); fm.Clear(); Assert.AreEqual(0, fm.Count); fm[g] = Element; Assert.IsTrue(fm.Contains(g)); Assert.IsFalse(fm.Contains("foo")); Assert.IsInstanceOfType(typeof(DiscoInfo), fm[g]); Assert.AreEqual(1, fm.Count); // re-read, to reparse fm = new FileMap<DiscoInfo>("test.xml", ef); Assert.IsTrue(fm.Contains(g)); Assert.IsInstanceOfType(typeof(DiscoInfo), fm[g]); fm[g] = null; Assert.AreEqual(1, fm.Count); fm.Remove(g); Assert.AreEqual(0, fm.Count); }
public static unsafe ResourceNode FromSource(ResourceNode parent, DataSource source) { ResourceNode n = null; if ((n = GetRaw(source)) != null) { n.Initialize(parent, source); } else { //Check for compression? if (Compressor.IsDataCompressed(source.Address, source.Length)) { if ((*(uint *)source.Address) == YAZ0.Tag) { YAZ0 *cmpr = (YAZ0 *)source.Address; try { //Expand the whole resource and initialize FileMap map = FileMap.FromTempFile((int)cmpr->_unCompDataLen); Compressor.Expand(cmpr, map.Address, map.Length); source.Compression = CompressionType.RunLength; //Check for a match if ((n = GetRaw(new DataSource(map.Address, map.Length))) != null) { n.Initialize(parent, source, new DataSource(map)); } } catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); } } else { CompressionHeader *cmpr = (CompressionHeader *)source.Address; if (Compressor.Supports(cmpr->Algorithm)) { try { //Expand a portion of the data byte *buffer = stackalloc byte[CompressBufferLen]; Compressor.Expand(cmpr, buffer, CompressBufferLen); //Check for a match if ((n = GetRaw(new DataSource(buffer, CompressBufferLen))) != null) { //Expand the whole resource and initialize FileMap map = FileMap.FromTempFile(cmpr->ExpandedSize); Compressor.Expand(cmpr, map.Address, map.Length); source.Compression = cmpr->Algorithm; n.Initialize(parent, source, new DataSource(map)); } } catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); } } } } } return(n); }
public DataSource(VoidPtr addr, int len, CompressionType compression) { Address = addr; Length = len; Map = null; Compression = compression; }
public virtual FileMap EncodeTEX0Texture(Bitmap src, int mipLevels) { int w = src.Width, h = src.Height; int bw = BlockWidth, bh = BlockHeight; PixelFormat fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb; FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels) + 0x40); try { //Build TEX header TEX0v1 *header = (TEX0v1 *)fileView.Address; * header = new TEX0v1(w, h, RawFormat, mipLevels); int sStep = bw * Image.GetPixelFormatSize(fmt) / 8; int dStep = bw * bh * BitsPerPixel / 8; using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt)) for (int i = 1; i <= mipLevels; i++) { EncodeLevel(header->PixelData, dib, src, dStep, sStep, i); } return(fileView); } catch (Exception x) { MessageBox.Show(x.ToString()); fileView.Dispose(); return(null); } }
IDictionary <UInt32, UInt32> CorrectOffsets() { var changes = new SortedDictionary <UInt32, UInt32>(); var list = FileMap.ToList(); var firstinstructioindex = list.FindIndex(x => x.Value is Bytecode.Instruction); var itemoffset = list[firstinstructioindex].Key; for (var i = firstinstructioindex; i >= 0 && i < list.Count; ++i) { var item = list[i]; if (itemoffset != item.Key) { var diff = itemoffset - item.Key; list[i] = new KeyValuePair <UInt32, Object>(itemoffset, item.Value); changes[item.Key] = itemoffset; } var size = (UInt32)GetObjectSize(item.Value); itemoffset += size; } FileMap.Clear(); foreach (var item in list) { FileMap.Add(item.Key, item.Value); } return(changes); }
IDictionary <UInt32, String> ReadStringMap(FileReader reader, FileHeaders.SCENARIO_HEADER header) { var map = new SortedDictionary <UInt32, String>(); reader.Stream.Position = header.StringTableOffset; while (true) { if (reader.Stream.Position == reader.Stream.Length) { break; } var offset = (UInt32)reader.Stream.Position; var str = reader.ReadString(); map.Add(offset, str); FileMap.Add(offset, str); if (str == "") { break; } } return(map); }
public unsafe virtual void ReplaceRaw(VoidPtr address, int length) { FileMap map = FileMap.FromTempFile(length); Memory.Move(map.Address, address, (uint)length); ReplaceRaw(map); }
public PatchListFile(string patchFile) { DataSource patchFileSource = new DataSource(FileMap.FromFile(patchFile)); _Header = patchFileSource.Slice(0, 0x80); VoidPtr addr = patchFileSource.Address + 4; _Files = new PatchFileItem[*(uint *)addr]; for (int i = 0; i < _Files.Length; i++) { string absolutePath = Encoding.ASCII.GetString(patchFileSource.Slice(0x80 + (i * 0x80), 0x80)); if (absolutePath.Contains('\0')) { absolutePath = absolutePath.Substring(0, absolutePath.IndexOf('\0')); } string relativePath = absolutePath; if (relativePath.Contains("/")) { relativePath = relativePath.Substring(relativePath.IndexOf("/") + 1); } if (absolutePath.Contains("packed")) { _Files[i] = new PatchFileItem(relativePath.Replace("packed", string.Empty), absolutePath.Replace("packed", string.Empty), true); } else { _Files[i] = new PatchFileItem(relativePath, absolutePath, false); } } patchFileSource.Close(); }
public ACMDFile OpenFile(string Filepath, int type) { DataSource source = new DataSource(FileMap.FromFile(Filepath)); if (*(buint *)source.Address != 0x41434D44) // ACMD { MessageBox.Show("Not an ACMD file:\n" + Filepath); return(null); } if (*(byte *)(source.Address + 0x04) == 0x02) { Runtime.WorkingEndian = Endianness.Little; } else if ((*(byte *)(source.Address + 0x04) == 0x00)) { Runtime.WorkingEndian = Endianness.Big; } else { return(null); } return(new ACMDFile(source)); }
public static unsafe void Scan(FileMap map, FileScanNode node) { using (ProgressWindow progress = new ProgressWindow(MainForm.Instance, "File Scanner", "Scanning for known file types, please wait...", true)) { progress.TopMost = true; progress.Begin(0, map.Length, 0); byte *data = (byte *)map.Address; uint i = 0; do { ResourceNode n = null; DataSource d = new DataSource(&data[i], 0); if ((n = NodeFactory.GetRaw(d)) != null) { if (!(n is MSBinNode)) { n.Initialize(node, d); try { i += (uint)n.WorkingSource.Length; } catch { } } } progress.Update(i + 1); }while (++i + 4 < map.Length); progress.Finish(); } }
public void GetFileEvents( ) { IFile file; var buffer = default(byte[]); var bytes = default(byte); long length; IFileEvents fileEvents = null; using (file = fMap.Get(TextFile)) { fileEvents = FileMap.GetFileEvents(file); file.Position = 0; length = file.Length; buffer = file.Read(length); } int eventCount = 0; fileEvents.Opened += (f) => { ++eventCount; }; fileEvents.Closed += (f) => { ++eventCount; }; --file.Position; using (file) { bytes = file.Read(); } Assert.AreEqual(2, eventCount); }
public unsafe virtual void ReplaceRaw(FileMap map) { if (_children != null && !RetainChildrenOnReplace) { foreach (ResourceNode node in _children) { node.Dispose(); } _children.Clear(); _children = null; } _replUncompSrc.Close(); _replSrc.Close(); _replSrc = new DataSource(map); FileMap uncompMap = Compressor.TryExpand(ref _replSrc, false); _compression = _replSrc.Compression; _replUncompSrc = uncompMap != null ? new DataSource(uncompMap) : _replSrc; _replaced = true; if (!OnInitialize() && !RetainChildrenOnReplace) { _children = new List <ResourceNode>(); } _replaced = false; _changed = false; if (Replaced != null) { Replaced(this); } }
public void TestCreate() { ElementFactory ef = new ElementFactory(); ef.AddType(new global::jabber.protocol.iq.Factory()); string g = new Guid().ToString(); FileMap <DiscoInfo> fm = new FileMap <DiscoInfo>("test.xml", ef); fm.Clear(); Assert.AreEqual(0, fm.Count); fm[g] = Element; Assert.IsTrue(fm.Contains(g)); Assert.IsFalse(fm.Contains("foo")); Assert.IsInstanceOfType(typeof(DiscoInfo), fm[g]); Assert.AreEqual(1, fm.Count); // re-read, to reparse fm = new FileMap <DiscoInfo>("test.xml", ef); Assert.IsTrue(fm.Contains(g)); Assert.IsInstanceOfType(typeof(DiscoInfo), fm[g]); fm[g] = null; Assert.AreEqual(1, fm.Count); fm.Remove(g); Assert.AreEqual(0, fm.Count); }
/// <summary> /// GC safe dispose wrapper /// </summary> /// <param name="disposing">truth check</param> protected virtual void Dispose(bool disposing) { if (Disposed) { return; } Hasher?.Dispose(); Prefetch.Dispose(); foreach (var(_, cache) in CacheFiles) { cache?.Dispose(); } if (disposing) { CacheFiles.Clear(); CacheFiles = default; FileMap.Clear(); FileMap = default; Prefetch = default; } Disposed = true; }
public void TestNull() { FileMap <Element> fm = new FileMap <Element>("test.xml", null); Assert.IsNotNull(fm); FileMap <DiscoInfo> fm2 = new FileMap <DiscoInfo>("test.xml", null); }
public void ConvertToV2() { int size = 0x08 + Entries.Count * 0x10; string path = _workingSource.Map.FilePath; _workingSource.Close(); _workingSource = new DataSource(FileMap.FromTempFile(size)); VoidPtr addr = _workingSource.Address; *(uint *)addr = 0x0002666f; *(int *)(addr + 4) = Entries.Count; addr += 0x08; for (int i = 0; i < Entries.Count; i++) { LSEntryObject lsobj = Entries.Values[i]; LSEntry_v2 * entry = (LSEntry_v2 *)(addr + (i * 0x10)); *entry = new LSEntry_v2() { _crc = lsobj.FileNameCRC, _start = lsobj.DTOffset, _size = lsobj.Size, _dtIndex = lsobj.DTIndex, _padlen = lsobj.PaddingLength }; } _workingSource.Export(path); }
public static FileMap FromJson(Dictionary <string, System.Object> json) { var t = new FileMap(); t.FileMap_SetFromJson(json); return(t); }
private IFileMap GetFileMap(FilePath path) { IFileMap result = null; if(_fileMappings.TryGetValue(path, out result) == false) { result = new FileMap(path); _fileMappings.Add(path, result); } return result; }
public void SetFile(int folderId, int fileId, FileMap fileMap) { //Debug.Log(string.Format("Setting Folder:{0} File:{1} to FileMap:'{2}'", folderId, fileId, fileMap)); int newFolders = folderId - Folders.Count + 1; if (newFolders > 0) Debug.Log("Adding " + newFolders.ToString() + " folders"); for (int i = 0; i < newFolders; i++) { Folders.Add(new FolderMap()); } Folders[folderId][fileId] = fileMap; }
public void ValidaGravacaoArquivo() { Ponto[,] matrizLabirinto = FileInstance.Read(); FileMap fileToSave = new FileMap("LabirintoSave.txt"); fileToSave.Save(matrizLabirinto); FileMap fileToRead = new FileMap("LabirintoSave.txt"); Ponto[,] matrizLeitura2 = fileToRead.Read(); foreach (Ponto p in matrizLeitura2) Assert.AreEqual(matrizLabirinto[p.Linha, p.Coluna].Tipo, matrizLeitura2[p.Linha, p.Coluna].Tipo); }
//1. Parse out all used file/folder ids public CharacterMap BuildMap(Spriter.Entity entity, GameObject root) { var files = new HashSet<Spriter.File>(); GetUsedFiles(entity, files); //Build a character map from the used sprites var charMap = root.AddComponent<CharacterMap>(); foreach(var file in files) { var fileMap = new FileMap { FilePath = file.Name, Sprite = file.GetSprite() }; charMap.SetFile(file.Folder.Id, file.Id, fileMap); } return charMap; }
public virtual FileMap EncodeTPLTextureIndexed(Bitmap src, int numColors, WiiPaletteFormat format, QuantizationAlgorithm algorithm, out FileMap paletteFile) { using (Bitmap indexed = src.Quantize(algorithm, numColors, RawFormat, format, null)) return EncodeTPLTextureIndexed(indexed, 1, format, out paletteFile); }
public MapFile(PSObject value, FileMap map) { Value = value; Map = map; }
public void Setup() { FileInfo file = new FileInfo(string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "Labirinto.txt")); FileInstance = new FileMap(file.FullName); }
public SystemMapFile(PSObject value, FileMap map) : base(value, map) { }
public static FileMap GenerateMap(string path) { var map = new FileMap(); var text = File.ReadAllText(path); map.LFUsed = text.Count(c => c == '\n'); map.CRLFUsed = text.Count(c => c == '\r'); map.LFUsed -= map.CRLFUsed; map.Lines = text.Replace("\r", "").Split('\n'); map.Indentation = new int[map.Lines.Length]; map.AverageSpaces = 0; int previousIndent = 0, currentIndent = 0; for (int i = 0; i < map.Lines.Length; i++) { string line = map.Lines[i]; int indent; if (string.IsNullOrWhiteSpace(line)) { map.Indentation[i] = -1; continue; } int spaces = 0; if (line.StartsWith(" ")) { map.SpacesUsed++; indent = CountStart(line, ' '); if (map.SpacesUsed != 0 && Math.Abs(indent - previousIndent) < (map.AverageSpaces / map.SpacesUsed) * 0.5) { // If it's less than half of the average away from the last indent, assume it's a mistake indent = previousIndent; } spaces = indent; } else if (line.StartsWith("\t")) { map.TabsUsed++; indent = CountStart(line, '\t') * GuessedTabSize; } else { previousIndent = currentIndent = 0; map.Indentation[i] = 0; continue; } if (previousIndent < indent && indent - previousIndent < IndentationThreshold) // Ignore indentation too far out there currentIndent++; else if (previousIndent > indent) currentIndent--; map.Indentation[i] = currentIndent; if (spaces != 0 && currentIndent != 0) map.AverageSpaces += spaces / currentIndent; previousIndent = indent; } for (int i = text.Length - 1; i >= 0; i--) { if (text[i] == '\n') map.TrailingLines++; else if (text[i] == '\r') ; else break; } return map; }
internal static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, FileMap dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, int dwNumberOfBytesToMap);
internal static extern IntPtr OpenFileMapping(FileMap dwDesiredAccess, // access mode bool bInheritHandle, // inherit flag string lpName // object name );
public DataSource(FileMap map) : this(map, CompressionType.None) { }
public new DialogResult ShowDialog(IWin32Window owner) { _bresParent = null; _origTEX0 = null; _origPLT0 = null; _origREFT = null; _origTPL = null; _origTPLPlt = null; _paletteData = _textureData = null; DialogResult = DialogResult.Cancel; try { return base.ShowDialog(owner); } //catch (Exception x) { MessageBox.Show(x.ToString()); return DialogResult.Cancel; } finally { DisposeImages(); } }
public virtual FileMap EncodeTPLTextureIndexed(Bitmap src, int mipLevels, WiiPaletteFormat format, out FileMap paletteFile) { if (!src.IsIndexed()) throw new ArgumentException("Source image must be indexed."); FileMap texMap = EncodeTPLTexture(src, mipLevels); paletteFile = EncodeTPLPalette(src.Palette, format); return texMap; }
public DataSource(VoidPtr addr, int len) { Address = addr; Length = len; Map = null; }
public void Close() { if (Map != null) { Map.Dispose(); Map = null; } Address = null; Length = 0; }
public DataSource(FileMap map) { Address = map.Address; Length = map.Length; Map = map; }
public void Initialize(ResourceNode parent, FileMap source) { Initialize(parent, new DataSource(source)); }
public unsafe virtual void ReplaceRaw(FileMap map) { if (_children != null) { foreach (ResourceNode node in _children) node.Dispose(); _children.Clear(); _children = null; } _replUncompSrc.Close(); _replSrc.Close(); if (Compressor.IsDataCompressed(map.Address, map.Length)) { CompressionHeader* cmpr = (CompressionHeader*)map.Address; _compression = cmpr->Algorithm; if (Compressor.Supports(cmpr->Algorithm)) { FileMap uncompMap = FileMap.FromTempFile(cmpr->ExpandedSize); Compressor.Expand(cmpr, uncompMap.Address, uncompMap.Length); _replSrc = new DataSource(map, cmpr->Algorithm); _replUncompSrc = new DataSource(uncompMap); } else _replSrc = _replUncompSrc = new DataSource(map); } else { _compression = CompressionType.None; _replSrc = _replUncompSrc = new DataSource(map); } _replaced = true; if (!OnInitialize()) _children = new List<ResourceNode>(); _replaced = false; _changed = false; if (Replaced != null) Replaced(this); }
public void TestNull() { FileMap<Element> fm = new FileMap<Element>("test.xml", null); Assert.IsNotNull(fm); FileMap<DiscoInfo> fm2 = new FileMap<DiscoInfo>("test.xml", null); }
public void EncodeSource() { TextureConverter format = TextureConverter.Get((WiiPixelFormat)cboFormat.SelectedItem); if (format.IsIndexed) { if (_origTEX0 != null || _bresParent != null) _textureData = format.EncodeTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); else if (_origREFT != null || _reftParent != null) _textureData = format.EncodeREFTTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem); else if (_origTPL != null || _tplParent != null) _textureData = format.EncodeTPLTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); } else { if ((format.RawFormat == WiiPixelFormat.CMPR) && (_cmprBuffer != null)) { if (_origTEX0 != null || _bresParent != null) _textureData = ((CMPR)format).EncodeTextureCached(_source, (int)numLOD.Value, _cmprBuffer); else if (_origREFT != null || _reftParent != null) _textureData = ((CMPR)format).EncodeREFTTextureCached(_source, (int)numLOD.Value, _cmprBuffer); else if (_origTPL != null || _tplParent != null) _textureData = ((CMPR)format).EncodeTPLTextureCached(_source, (int)numLOD.Value, _cmprBuffer); } else if (_origTEX0 != null || _bresParent != null) _textureData = format.EncodeTEX0Texture(_source, (int)numLOD.Value); else if (_origREFT != null || _reftParent != null) _textureData = format.EncodeREFTTexture(_source, (int)numLOD.Value, WiiPaletteFormat.IA8); else if (_origTPL != null || _tplParent != null) _textureData = format.EncodeTPLTexture(_source, (int)numLOD.Value); } if (_bresParent != null) { _origTEX0 = _bresParent.CreateResource<TEX0Node>(Path.GetFileNameWithoutExtension(_imageSource)); if (_paletteData != null) { _origPLT0 = _bresParent.CreateResource<PLT0Node>(_origTEX0.Name); _origPLT0.Name = _origTEX0.Name; _origPLT0.ReplaceRaw(_paletteData); } _origTEX0.ReplaceRaw(_textureData); } else if (_tplParent != null) { _origTPL = new TPLTextureNode() { Name = "Texture" }; _tplParent.AddChild(_origTPL); _origTPL.ReplaceRaw(_textureData); if (_paletteData != null) { _origTPLPlt = new TPLPaletteNode() { Name = "Palette" }; _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } } else if (_reftParent != null) { _reftParent.AddChild(_origREFT = new REFTEntryNode() { Name = Path.GetFileNameWithoutExtension(_imageSource) }); _origREFT.ReplaceRaw(_textureData); } else if (_origTEX0 != null) { if (_origPLT0 != null) { if (_paletteData != null) _origPLT0.ReplaceRaw(_paletteData); else { _origPLT0.Remove(); _origPLT0.Dispose(); } } else if (_paletteData != null) { if ((_origTEX0.Parent == null) || (_origTEX0.Parent.Parent == null)) { _paletteData.Dispose(); _paletteData = null; } else { _bresParent = _origTEX0.Parent.Parent as BRESNode; _origPLT0 = _bresParent.CreateResource<PLT0Node>(_origTEX0.Name); _origPLT0.Name = _origTEX0.Name; _origPLT0.ReplaceRaw(_paletteData); } } _origTEX0.ReplaceRaw(_textureData); } else if (_origREFT != null) _origREFT.ReplaceRaw(_textureData); else if (_origTPL != null) { _origTPL.ReplaceRaw(_textureData); if (_origTPLPlt != null) { if (_paletteData != null) { _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } else { _origTPLPlt.Remove(); _origTPLPlt.Dispose(); } } else if (_paletteData != null) { if (_origTPL.Parent == null) { _paletteData.Dispose(); _paletteData = null; } else { _origTPLPlt = new TPLPaletteNode() { _name = "Palette" }; _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } } } }