From 1c0026f81d6bd9ed65719e96a9e964d468bf7ad3 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 21 Jan 2014 11:40:50 +0000 Subject: [PATCH] Core: XmlNode::Remove, plugin/zip: Fixed git-svn-id: svn://ultimatepp.org/upp/trunk@6802 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/XML.cpp | 5 +++++ uppsrc/Core/XML.h | 1 + uppsrc/Core/src.tpp/XmlNode$en-us.tpp | 4 ++++ uppsrc/Core/z.cpp | 19 ++++++++++++------- uppsrc/XmlView/main.cpp | 6 +++--- uppsrc/plugin/zip/UnZip.cpp | 5 +++-- uppsrc/plugin/zip/Zip.cpp | 5 +++-- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/uppsrc/Core/XML.cpp b/uppsrc/Core/XML.cpp index 43a899799..f7ed0bbcd 100644 --- a/uppsrc/Core/XML.cpp +++ b/uppsrc/Core/XML.cpp @@ -784,6 +784,11 @@ const XmlNode& XmlNode::operator[](const char *tag) const return q < 0 ? Void() : node[q]; } +void XmlNode::Remove(int i) +{ + node.Remove(i); +} + void XmlNode::Remove(const char *tag) { int q = FindTag(tag); diff --git a/uppsrc/Core/XML.h b/uppsrc/Core/XML.h index 0eed66e8f..ed1b1b0a8 100644 --- a/uppsrc/Core/XML.h +++ b/uppsrc/Core/XML.h @@ -193,6 +193,7 @@ public: const XmlNode& operator[](int i) const { return i >= 0 && i < node.GetCount() ? node[i] : Void(); } const XmlNode& operator[](const char *tag) const; XmlNode& Add() { return node.Add(); } + void Remove(int i); void AddText(const String& txt) { Add().CreateText(txt); } int FindTag(const char *tag) const; XmlNode& Add(const char *tag); diff --git a/uppsrc/Core/src.tpp/XmlNode$en-us.tpp b/uppsrc/Core/src.tpp/XmlNode$en-us.tpp index 7d40eb6b0..18aa46637 100644 --- a/uppsrc/Core/src.tpp/XmlNode$en-us.tpp +++ b/uppsrc/Core/src.tpp/XmlNode$en-us.tpp @@ -134,6 +134,10 @@ If no such node is found, returns Void().&] [s5;:XmlNode`:`:Add`(`): [_^XmlNode^ XmlNode][@(0.0.255) `&]_[* Add]()&] [s2;%% Adds a new sub`-node.&] [s3;%% &] +[s4; &] +[s5;:XmlNode`:`:Remove`(int`): [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i])&] +[s2;%% Removes subnode at [%-*@3 i].&] +[s3;%% &] [s4;%% &] [s5;:XmlNode`:`:AddText`(const String`&`): [@(0.0.255) void]_[* AddText]([@(0.0.255) const]_ [_^String^ String][@(0.0.255) `&]_[*@3 txt])&] diff --git a/uppsrc/Core/z.cpp b/uppsrc/Core/z.cpp index da4e325ff..c46d3f2ae 100644 --- a/uppsrc/Core/z.cpp +++ b/uppsrc/Core/z.cpp @@ -312,10 +312,10 @@ int64 CopyStream(Stream& dest, Stream& src, int64 count, Gate2 pro int loaded; int64 done = 0; int64 total = count; - while(count > 0 && (loaded = src.Get(temp, (int)min(count, block))) > 0) { + while(count > 0 && (loaded = src.Get(~temp, (int)min(count, block))) > 0) { if(progress(done, total)) return -1; - dest.Put(temp.operator const byte *(), loaded); + dest.Put(~temp, loaded); count -= loaded; done += loaded; } @@ -323,20 +323,25 @@ int64 CopyStream(Stream& dest, Stream& src, int64 count, Gate2 pro } int64 zPress(Stream& out, Stream& in, int64 size, Gate2 progress, bool gzip, bool compress, - dword *crc = NULL) + dword *crc = NULL, bool hdr = true) { Zlib zlib; - zlib.GZip(gzip).CRC(crc); - bool r; + zlib.GZip(gzip).CRC(crc).Header(hdr); + + int64 r = -1; { OutFilterStream outs(out, zlib); if(compress) zlib.Compress(); else zlib.Decompress(); - r = CopyStream(outs, in, size, progress) >= 0 && !out.IsError() ? outs.GetCount() : -1; + if(CopyStream(outs, in, size, progress) >= 0) { + outs.Close(); + if(!out.IsError() && !outs.IsError()) + r = outs.GetCount(); + } } - if(r && crc) + if(r >= 0 && crc) *crc = zlib.GetCRC(); return r; } diff --git a/uppsrc/XmlView/main.cpp b/uppsrc/XmlView/main.cpp index cd22abb6c..c21f42966 100644 --- a/uppsrc/XmlView/main.cpp +++ b/uppsrc/XmlView/main.cpp @@ -39,8 +39,8 @@ void XmlView::Load(const char *filename) int64 l = GetFileLength(filename); if(l < 0 || l > 16000000) return; - String txt = LoadFile(filename); - XmlParser p(txt); + FileIn in(filename); + XmlParser p(in); xml.Clear(); try { while(!p.IsEof()) @@ -49,7 +49,7 @@ void XmlView::Load(const char *filename) catch(XmlError e) { error = "XML parsing error: " + e; view.Show(); - view <<= txt; + view <<= LoadFile(filename); view.SetCursor(view.GetPos(p.GetLine() - 1, p.GetColumn() - 1)); view.SetFocus(); return; diff --git a/uppsrc/plugin/zip/UnZip.cpp b/uppsrc/plugin/zip/UnZip.cpp index c84d4cd79..4b225c57e 100644 --- a/uppsrc/plugin/zip/UnZip.cpp +++ b/uppsrc/plugin/zip/UnZip.cpp @@ -43,7 +43,8 @@ void UnZip::SkipFile() ReadHeader(); } -int64 zPress(Stream& out, Stream& in, int64 size, Gate2 progress, bool gzip, bool compress, dword *crc); +int64 zPress(Stream& out, Stream& in, int64 size, Gate2 progress, bool gzip, + bool compress, dword *crc, bool hdr); bool UnZip::ReadFile(Stream& out, Gate2 progress) { @@ -68,7 +69,7 @@ bool UnZip::ReadFile(Stream& out, Gate2 progress) } else if(method == 8) - l = (int)zPress(out, *zip, csize, AsGate64(progress), true, false, &crc); + l = (int)zPress(out, *zip, csize, AsGate64(progress), false, false, &crc, false); else { SetError(); return false; diff --git a/uppsrc/plugin/zip/Zip.cpp b/uppsrc/plugin/zip/Zip.cpp index 9f12b81d6..0f13c5bcb 100644 --- a/uppsrc/plugin/zip/Zip.cpp +++ b/uppsrc/plugin/zip/Zip.cpp @@ -10,7 +10,8 @@ void Zip::WriteFolder(const char *path, Time tm) WriteFile(~p, 0, p, false, tm); } -int64 zPress(Stream& out, Stream& in, int64 size, Gate2 progress, bool gzip, bool compress, dword *crc); +int64 zPress(Stream& out, Stream& in, int64 size, Gate2 progress, bool gzip, + bool compress, dword *crc, bool hdr); void Zip::WriteFile(const void *ptr, int size, const char *path, Gate2 progress, Time tm) { @@ -19,7 +20,7 @@ void Zip::WriteFile(const void *ptr, int size, const char *path, Gate2 StringStream ss; MemReadStream ms(ptr, size); dword crc; - zPress(ss, ms, size, AsGate64(progress), true, true, &crc); + zPress(ss, ms, size, AsGate64(progress), false, true, &crc, false); String data = ss.GetResult(); const void *r = ~data; int csize = data.GetLength();