void PtexReader::readEditData() { // determine file range to scan for edits FilePos pos = FilePos(_editdatapos), endpos; if (_extheader.editdatapos > 0) { // newer files record the edit data position and size in the extheader // note: position will be non-zero even if size is zero endpos = FilePos(pos + _extheader.editdatasize); } else { // must have an older file, just read until EOF endpos = FilePos((uint64_t)-1); } while (pos < endpos) { seek(pos); // read the edit data header uint8_t edittype = et_editmetadata; uint32_t editsize; if (!readBlock(&edittype, sizeof(edittype), /*reporterror*/ false)) break; if (!readBlock(&editsize, sizeof(editsize), /*reporterror*/ false)) break; if (!editsize) break; _hasEdits = true; pos = tell() + editsize; switch (edittype) { case et_editfacedata: readEditFaceData(); break; case et_editmetadata: readEditMetaData(); break; } } }
void Archive::readTOC() { const char* idx = info.get(); for (int i = 0; i < 10000; ++i, idx += 8) { const int offs = read_i32(idx); if (offs) scenarios[i] = FilePos(info.get() + offs, read_i32(idx + 4)); } }
static int FileScroll( a_window *wnd, int lines ) { int old_top; old_top = WndTop( wnd ); FilePos( wnd, old_top + lines ); return( WndTop( wnd ) - old_top ); }
void Archive::readOverrides() { // Iterate over all files in the directory and override the table of contents // if there is a free SEENXXXX.TXT file. fs::path seen_dir = fs::path(name).branch_path(); fs::directory_iterator end; for (fs::directory_iterator it(seen_dir); it != end; ++it) { string filename = it->leaf(); if (filename.size() == 12 && istarts_with(filename, "seen") && iends_with(filename, ".txt") && isdigit(filename[4]) && isdigit(filename[5]) && isdigit(filename[6]) && isdigit(filename[7])) { Mapping* mapping = new Mapping((seen_dir / filename).string(), Read); maps_to_delete_.push_back(mapping); int index = lexical_cast<int>(filename.substr(4, 4)); scenarios[index] = FilePos(mapping->get(), mapping->size()); } } }
bool PtexReader::open(const char* path, Ptex::String& error) { if (!LittleEndian()) { error = "Ptex library doesn't currently support big-endian cpu's"; return 0; } _path = path; _fp = _io->open(path); if (!_fp) { std::string errstr = "Can't open ptex file: "; errstr += path; errstr += "\n"; errstr += _io->lastError(); error = errstr.c_str(); return 0; } readBlock(&_header, HeaderSize); if (_header.magic != Magic) { std::string errstr = "Not a ptex file: "; errstr += path; error = errstr.c_str(); return 0; } if (_header.version != 1) { char ver[21]; snprintf(ver, 20, "%d", _header.version); std::string errstr = "Unsupported ptex file version ("; errstr += ver; errstr += "): "; errstr += path; error = errstr.c_str(); return 0; } _pixelsize = _header.pixelSize(); // read extended header memset(&_extheader, 0, sizeof(_extheader)); readBlock(&_extheader, PtexUtils::min(uint32_t(ExtHeaderSize), _header.extheadersize)); // compute offsets of various blocks FilePos pos = tell(); _faceinfopos = pos; pos += _header.faceinfosize; _constdatapos = pos; pos += _header.constdatasize; _levelinfopos = pos; pos += _header.levelinfosize; _leveldatapos = pos; pos += _header.leveldatasize; _metadatapos = pos; pos += _header.metadatazipsize; pos += sizeof(uint64_t); // compatibility barrier _lmdheaderpos = pos; pos += _extheader.lmdheaderzipsize; _lmddatapos = pos; pos += _extheader.lmddatasize; // edit data may not start immediately if additional sections have been added // use value from extheader if present (and > pos) _editdatapos = PtexUtils::max(FilePos(_extheader.editdatapos), pos); // read basic file info readFaceInfo(); readConstData(); readLevelInfo(); readEditData(); // an error occurred while reading the file if (!_ok) { error = _error.c_str(); return 0; } return 1; }
//Write the file back out, with the changes bool BlueZip::Write(bool Store) { //TODO: Do not use a TempFile, send straight to the output char TempFileName[MAX_PATH]; File f; zList* z; zList** next = &Files; //where to insert the next zList int i, j; //global enumeration variables if ((Files == NULL) && (Pending == NULL)) { ErrMsg("Blank ZIP files not allowed"); return false; } //Always use a temporary file name (they may have the ZIP file on a floppy) f = FileOpenTemp(TempFileName); if (!FileValid(f)) { ErrMsg(Failed to open the temporary file); return false; } if (Files != NULL) { File Orig = FileOpenRead(FileName); if (!FileValid(Orig)) { ErrMsg("Failed to open the reading file"); return false; } const int BlockSize = 4096; char* Buffer = new char[BlockSize]; datCentral hLocal; for (z = Files; z != NULL; z = z->next) { if (!z->Delete) { //Remove any that have dropped out of the list *next = z; next = &z->next; //Perform a ZIP copy SeekBeg(Orig, z->data.Offset + z->FileDeltaPos); z->data.Offset = FilePos(f); u32 sig; FileRead(Orig, &sig, 4); Assert(sig == sigLocal); FileWrite(f, &sig, 4); hLocal.ReadLocal(Orig); hLocal.WriteLocal(f); i = hLocal.CompSize + hLocal.lFileName + hLocal.lExtra; while(i != 0) { j = min(i, BlockSize); FileRead(Orig, Buffer, j); FileWrite(f, Buffer, j); i -= j; } } } FileClose(Orig); delete[] Buffer; } while (Pending != NULL) { fList* fAdd = Pending; Pending = Pending->next; z = fAdd->ZipUp(f, Store); if (z == NULL) { ErrMsg("Failed to add the file"); } else { *next = z; next = &z->next; } delete fAdd; } //Write out the central header data.Count = 0; data.Offset = FilePos(f); for (z = Files; z != NULL; z = z->next, data.Count++) z->WriteCentral(f); data.Size = FilePos(f) - data.Offset; WriteEnd(f); FileClose(f); //Using a temp file if (!FileReplace(FileName, TempFileName)) { ErrMsg("Failed to copy the temporary file"); return false; } return true; }
void TextFormatter::FormatPlainText(CFDC& dc, int& width, int& height, int fontsize, const wchar_t *text, int len, LineArray& lines) { lines.RemoveAll(); int save_width = m_width; bool save_justified = m_justified; m_width = width; m_justified = false; const wchar_t *top = text + len; Attr attr; attr.wa = 0; attr.fsize = fontsize; int curh = 0; while (text < top && curh < height) { const wchar_t *p_end = text; while (p_end < top && *p_end != '\r' && *p_end != '\n') ++p_end; Paragraph p(p_end - text); memcpy(p.str, text, (p_end - text)*sizeof(wchar_t)); for (int i = 0; i < p.cflags.size(); ++i) p.cflags[i].wa = attr.wa; p.findent = 3; // XXX int last = lines.GetSize(); FilePos fp = FilePos(); int lh = WrapLine(dc, p, fp, lines, curh, height - curh); if (lh < 0) { // it still might add something while (last < lines.GetSize()) curh += lines[last++].height; break; } curh += lh; while (p_end < top && (*p_end == '\r' || *p_end == '\n')) ++p_end; text = p_end; } m_width = save_width; m_justified = save_justified; // deduct ispace int min_ispace = -1, max_width = 0; for (int i = 0; i < lines.GetSize(); ++i) { const Line& ll = lines[i]; int w = 0; for (int j = 0; j < ll.dx.size(); ++j) w += ll.dx[j]; w += ll.ispace; if (max_width < w) max_width = w; if (min_ispace<0 || min_ispace>ll.ispace) min_ispace = ll.ispace; } if (min_ispace > 0) { for (int i = 0; i < lines.GetSize(); ++i) lines[i].ispace -= min_ispace; max_width -= min_ispace; } height = curh; width = max_width; }
bool TextFormatter::FormatBack(CFDC& dc, FilePos start, FilePos prev_top) { AdjustPos(start, true); if (start.para == 0 && start.off == 0) return false; // at the top m_lines.RemoveAll(); m_bot = start; for (int page = m_pages - 1; page >= 0; --page) { LineArray tmp; FilePos pos = start; int h = 0; // while there are still paragrahs before while (h < m_height && (pos.para>0 || pos.off > 0)) { // format entire paragraph LineArray cp; Paragraph para(m_tf->GetParagraph(pos.docid, pos.para)); if (pos.off < para.len) // double check args para.len = pos.off; else pos.off = para.len; FilePos fp = FilePos(pos.para, 0, pos.docid); WrapLine(dc, para, fp, cp, 0, 32768); // insert the formatted paragraph at start of list tmp.InsertAt(0, &cp); for (int i = 0; i < cp.GetSize(); ++i) h += cp[i].height; pos.off = 0; AdjustPos(pos, true); } // delete extra lines int j; // remove top lines for (h = 0, j = tmp.GetUpperBound(); j >= 0 && h + tmp[j].height <= m_height; --j) h += tmp[j].height; if (j < tmp.GetUpperBound()) { if (j >= 0 && prev_top != 0 && tmp[j + 1].pos >= prev_top) { --j; tmp.RemoveAt(0, j + 1); // now remove bottom lines for (h = j = 0; j < tmp.GetSize() && h + tmp[j].height <= m_height; ++j) h += tmp[j].height; if (j < tmp.GetSize()) tmp.RemoveAt(j, tmp.GetSize() - j); } else { tmp.RemoveAt(0, j + 1); } } // save lines m_lines.InsertAt(0, &tmp); m_pagelen.SetAtGrow(page, tmp.GetSize()); start = m_lines[0].pos; if (start.para == 0 && start.off == 0) // we reached the top of file return FormatFwd(dc, FilePos(0, 0, start.docid)); } // save positions m_top = m_lines[0].pos; Highlight(); // add one dummy line always Line l; l.pos = m_bot; m_lines.Add(l); return true; }
static void FileTrack( a_window *wnd, cue_handle *ch ) { unsigned active, old_active; unsigned end_line; int slack; file_window *file = WndFile( wnd ); mod_handle mod; cue_fileid id; wnd_row curr_row; int curr_piece; if( ch == NULL ) { mod = NO_MOD; id = 0; } else { mod = CueMod( ch ); id = CueFileId( ch ); } if( file->viewhndl == NULL || file->mod != mod || file->file_id != id ) { if( file->viewhndl != NULL ) { FDoneSource( file->viewhndl ); } file->mod = mod; file->file_id = id; FileSetDotAddr( wnd, GetCodeDot() ); if( file->mod == NO_MOD ) { file->viewhndl = NULL; } else { file->viewhndl = OpenSrcFile( ch ); } FileSetTitle( wnd, mod ); SeekToTheEnd( file ); file->eof = UINT_MAX; WndZapped( wnd ); FilePosInit( wnd ); file->active = NOT_ACTIVE; FilePos( wnd, 0 ); DbgUpdate( UP_OPEN_CHANGE ); } active = ActiveLine(); if( active != file->active ) { FileSetDotAddr( wnd, GetCodeDot() ); WndGetCurrent( wnd, &curr_row, &curr_piece ); WndNoCurrent( wnd ); if( curr_row != WND_NO_ROW ) { WndRowDirty( wnd, curr_row ); } } old_active = file->active; file->active = NOT_ACTIVE; slack = WndRows( wnd ) / 4; if( slack > 2 ) slack = 2; end_line = WndTop( wnd ) + WndRows( wnd ) - 1; if( old_active == NOT_ACTIVE || active > end_line ) { WndZapped( wnd ); WndScroll( wnd, active - slack - WndTop( wnd ) ); } else if( active > end_line - slack ) { WndRowDirtyImmed( wnd, old_active ); WndScroll( wnd, WndRows( wnd ) - 2 * slack ); } else if( active < WndTop( wnd ) ) { WndRowDirtyImmed( wnd, old_active ); WndScroll( wnd, active - WndTop( wnd ) - slack ); } else { WndRowDirty( wnd, old_active ); } WndNewCurrent( wnd, active, PIECE_SOURCE ); WndRowDirty( wnd, active ); file->active = active; }