Core: XmlNode::Remove, plugin/zip: Fixed

git-svn-id: svn://ultimatepp.org/upp/trunk@6802 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-01-21 11:40:50 +00:00
parent dd7aefb1b7
commit 1c0026f81d
7 changed files with 31 additions and 14 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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])&]

View file

@ -312,10 +312,10 @@ int64 CopyStream(Stream& dest, Stream& src, int64 count, Gate2<int64, int64> pro
int loaded;
int64 done = 0;
int64 total = count;
while(count > 0 && (loaded = src.Get(temp, (int)min<int64>(count, block))) > 0) {
while(count > 0 && (loaded = src.Get(~temp, (int)min<int64>(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<int64, int64> pro
}
int64 zPress(Stream& out, Stream& in, int64 size, Gate2<int64, int64> 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;
}

View file

@ -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;

View file

@ -43,7 +43,8 @@ void UnZip::SkipFile()
ReadHeader();
}
int64 zPress(Stream& out, Stream& in, int64 size, Gate2<int64, int64> progress, bool gzip, bool compress, dword *crc);
int64 zPress(Stream& out, Stream& in, int64 size, Gate2<int64, int64> progress, bool gzip,
bool compress, dword *crc, bool hdr);
bool UnZip::ReadFile(Stream& out, Gate2<int, int> progress)
{
@ -68,7 +69,7 @@ bool UnZip::ReadFile(Stream& out, Gate2<int, int> 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;

View file

@ -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<int64, int64> progress, bool gzip, bool compress, dword *crc);
int64 zPress(Stream& out, Stream& in, int64 size, Gate2<int64, int64> progress, bool gzip,
bool compress, dword *crc, bool hdr);
void Zip::WriteFile(const void *ptr, int size, const char *path, Gate2<int, int> progress, Time tm)
{
@ -19,7 +20,7 @@ void Zip::WriteFile(const void *ptr, int size, const char *path, Gate2<int, int>
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();