mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor to get rid of all the duplication; writing version info (dunno if it works)
This commit is contained in:
@@ -367,21 +367,26 @@ public abstract class Bin {
|
||||
|
||||
@Override
|
||||
public long sizeInBytes() {
|
||||
throw new UnsupportedOperationException();
|
||||
return bytesToSkip(getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException {
|
||||
if (stream instanceof OffsetTrackingInputStream) {
|
||||
long offset = ((OffsetTrackingInputStream) stream).getOffset();
|
||||
int offsetMask = myBytes-1;
|
||||
long offsetBits = offset & offsetMask;
|
||||
if (offsetBits > 0) {
|
||||
stream.skipBytes((int) (myBytes - offsetBits));
|
||||
int skip = bytesToSkip(offset);
|
||||
if (skip > 0) {
|
||||
stream.skipBytes(skip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int bytesToSkip(long offset) {
|
||||
int offsetMask = myBytes-1;
|
||||
long offsetBits = offset & offsetMask;
|
||||
return offsetBits == 0 ? 0 : (int) (myBytes - offsetBits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException {
|
||||
}
|
||||
@@ -468,7 +473,7 @@ public abstract class Bin {
|
||||
|
||||
@Override
|
||||
public long sizeInBytes() {
|
||||
throw new UnsupportedOperationException();
|
||||
return myValue.length() * 2 + 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -484,7 +489,10 @@ public abstract class Bin {
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
for (int i = 0; i < myValue.length(); i++) {
|
||||
stream.writeShort(BitsUtil.revertBytesOfShort((short) myValue.charAt(i)));
|
||||
}
|
||||
stream.writeShort(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -580,23 +588,6 @@ public abstract class Bin {
|
||||
writer.write(myBuffer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public String getAsWChar() {
|
||||
StringBuilder result = new StringBuilder(myBytes.length/2);
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(myBytes);
|
||||
DataInputStream dis = new DataInputStream(bis);
|
||||
try {
|
||||
for (int i = 0; i < myBytes.length / 2 - 1; i++) {
|
||||
result.append(BitsUtil.readChar(dis));
|
||||
}
|
||||
char terminator = BitsUtil.readChar(dis);
|
||||
assert terminator == '\0';
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArrayOfBins<T extends Bin> extends Bin {
|
||||
|
||||
@@ -17,34 +17,13 @@
|
||||
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class StringFileInfo extends Bin.Structure {
|
||||
public class StringFileInfo extends VersionInfoBin {
|
||||
public StringFileInfo() {
|
||||
super("StringFileInfo");
|
||||
addMember(new Word("wLength"));
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new Bytes("szKey", 30));
|
||||
addMember(new Padding(4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException {
|
||||
OffsetTrackingInputStream inputStream = (OffsetTrackingInputStream) stream;
|
||||
long startOffset = inputStream.getOffset();
|
||||
super.read(stream);
|
||||
assert ((Bytes) getMember("szKey")).getAsWChar().equals("StringFileInfo");
|
||||
long length = getValue("wLength");
|
||||
int i = 0;
|
||||
while(inputStream.getOffset() < startOffset + length) {
|
||||
StringTable stringTableReader = new StringTable("StringTable" + (i++));
|
||||
stringTableReader.read(inputStream);
|
||||
addMember(stringTableReader);
|
||||
}
|
||||
super("StringFileInfo", "StringFileInfo", new VersionInfoFactory() {
|
||||
@Override
|
||||
public VersionInfoBin createChild(int index) {
|
||||
return new StringTable("StringTable" + index);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,33 +17,14 @@
|
||||
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class StringTable extends Bin.Structure {
|
||||
public class StringTable extends VersionInfoBin {
|
||||
|
||||
public StringTable(String name) {
|
||||
super(name);
|
||||
addMember(new Word("wLength"));
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new WChar("szKey"));
|
||||
addMember(new Padding(4));
|
||||
}
|
||||
|
||||
public void read(DataInput stream) throws IOException {
|
||||
OffsetTrackingInputStream inputStream = (OffsetTrackingInputStream) stream;
|
||||
long startOffset = inputStream.getOffset();
|
||||
super.read(stream);
|
||||
long length = getValue("wLength");
|
||||
int i = 0;
|
||||
while(inputStream.getOffset() < startOffset + length) {
|
||||
StringTableEntry stringTableEntry = new StringTableEntry();
|
||||
stringTableEntry.read(inputStream);
|
||||
addMember(stringTableEntry);
|
||||
}
|
||||
super(name, null, new VersionInfoFactory() {
|
||||
@Override
|
||||
public VersionInfoBin createChild(int index) {
|
||||
return new StringTableEntry();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,20 +17,12 @@
|
||||
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StringTableEntry extends Bin.Structure {
|
||||
public class StringTableEntry extends VersionInfoBin {
|
||||
public StringTableEntry() {
|
||||
super("<unnamed>");
|
||||
addMember(new Word("wLength"));
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new WChar("szKey"));
|
||||
addMember(new Padding(4));
|
||||
addMember(new WChar("Value"));
|
||||
addMember(new Padding(4));
|
||||
}
|
||||
|
||||
@@ -1,32 +1,11 @@
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class Var extends Bin.Structure {
|
||||
public class Var extends VersionInfoBin {
|
||||
public Var(String name) {
|
||||
super(name);
|
||||
addMember(new Word("wLength"));
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new Bytes("szKey", 24));
|
||||
addMember(new Padding(4));
|
||||
super(name, "Translation");
|
||||
addMember(new DWord("Translation"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException {
|
||||
OffsetTrackingInputStream inputStream = (OffsetTrackingInputStream) stream;
|
||||
long startOffset = inputStream.getOffset();
|
||||
assert startOffset % 4 == 0;
|
||||
super.read(stream);
|
||||
String varKey = ((Bytes) getMember("szKey")).getAsWChar();
|
||||
assert varKey.equals("Translation"): "Expected key name Translation, found " + varKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,15 @@
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class VarFileInfo extends Bin.Structure {
|
||||
public class VarFileInfo extends VersionInfoBin {
|
||||
public VarFileInfo() {
|
||||
super("VarFileInfo");
|
||||
addMember(new Word("wLength"));
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new Bytes("szKey", 24));
|
||||
addMember(new Padding(4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException {
|
||||
OffsetTrackingInputStream inputStream = (OffsetTrackingInputStream) stream;
|
||||
long startOffset = inputStream.getOffset();
|
||||
super.read(stream);
|
||||
assert ((Bytes) getMember("szKey")).getAsWChar().equals("VarFileInfo");
|
||||
long length = getValue("wLength");
|
||||
int i = 0;
|
||||
while(inputStream.getOffset() < startOffset + length) {
|
||||
Var varReader = new Var("Var" + (i++));
|
||||
varReader.read(inputStream);
|
||||
addMember(varReader);
|
||||
}
|
||||
super("VarFileInfo", "VarFileInfo", new VersionInfoFactory() {
|
||||
@Override
|
||||
public VersionInfoBin createChild(int index) {
|
||||
return new Var("Var" + index);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,20 +17,14 @@
|
||||
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class VersionInfo extends Bin.Structure {
|
||||
public class VersionInfo extends VersionInfoBin {
|
||||
public VersionInfo() {
|
||||
super("VersionInfo");
|
||||
addMember(new Word("wLength"));
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new Bytes("szKey", 32));
|
||||
addMember(new Padding(4));
|
||||
super("VersionInfo", "VS_VERSION_INFO");
|
||||
addMember(new FixedFileInfo());
|
||||
addMember(new Padding(4));
|
||||
addMember(new StringFileInfo());
|
||||
@@ -44,8 +38,6 @@ public class VersionInfo extends Bin.Structure {
|
||||
startOffset = ((OffsetTrackingInputStream) stream).getOffset();
|
||||
}
|
||||
super.read(stream);
|
||||
String signature = ((Bytes) getMember("szKey")).getAsWChar();
|
||||
assert signature.equals("VS_VERSION_INFO"): "Expected signature VS_VERSION_INFO, found '" + signature + "'";
|
||||
if (stream instanceof OffsetTrackingInputStream) {
|
||||
long offset = ((OffsetTrackingInputStream) stream).getOffset();
|
||||
long length = getValue("wLength");
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
import com.pme.exe.Bin;
|
||||
import com.pme.util.OffsetTrackingInputStream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class VersionInfoBin extends Bin.Structure {
|
||||
private String myExpectedName;
|
||||
private VersionInfoFactory myChildFactory;
|
||||
|
||||
public VersionInfoBin(String name) {
|
||||
super(name);
|
||||
Word length = new Word("wLength");
|
||||
addMember(length);
|
||||
addSizeHolder(length);
|
||||
addMember(new Word("wValueLength"));
|
||||
addMember(new Word("wType"));
|
||||
addMember(new WChar("szKey"));
|
||||
addMember(new Padding(4));
|
||||
}
|
||||
|
||||
public VersionInfoBin(String versionInfo, String expectedName) {
|
||||
this(versionInfo);
|
||||
myExpectedName = expectedName;
|
||||
}
|
||||
|
||||
public VersionInfoBin(String versionInfo, String expectedName, VersionInfoFactory childFactory) {
|
||||
this(versionInfo, expectedName);
|
||||
myChildFactory = childFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException {
|
||||
OffsetTrackingInputStream inputStream = (OffsetTrackingInputStream) stream;
|
||||
long startOffset = inputStream.getOffset();
|
||||
assert startOffset % 4 == 0;
|
||||
super.read(stream);
|
||||
if (myExpectedName != null) {
|
||||
String signature = ((WChar) getMember("szKey")).getValue();
|
||||
assert signature.equals(myExpectedName): "Expected signature " + myExpectedName + ", found '" + signature + "'";
|
||||
}
|
||||
if (myChildFactory != null) {
|
||||
long length = getValue("wLength");
|
||||
int i = 0;
|
||||
while(inputStream.getOffset() < startOffset + length) {
|
||||
VersionInfoBin child = myChildFactory.createChild(i++);
|
||||
child.read(inputStream);
|
||||
addMember(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.pme.exe.res.vi;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public interface VersionInfoFactory {
|
||||
VersionInfoBin createChild(int index);
|
||||
}
|
||||
@@ -79,6 +79,10 @@ public class LauncherGenerator {
|
||||
RandomAccessFile exeStream = new RandomAccessFile(myExePath, "rw");
|
||||
myReader.write(exeStream);
|
||||
exeStream.close();
|
||||
|
||||
RandomAccessFile versionInfoStream = new RandomAccessFile(myExePath + ".version", "rw");
|
||||
myVersionInfo.resetOffsets(0);
|
||||
myVersionInfo.write(versionInfoStream);
|
||||
}
|
||||
|
||||
public void setResourceString(int id, String value) {
|
||||
|
||||
Reference in New Issue
Block a user