Skip to content

Commit

Permalink
Add write support for GroupIconDirectory and its entries (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
swismer committed May 19, 2023
1 parent 90f3a2c commit 95bc3a8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,45 @@
package com.kichik.pecoff4j.resources;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.kichik.pecoff4j.io.DataReader;
import com.kichik.pecoff4j.io.IDataReader;
import com.kichik.pecoff4j.io.IDataWriter;
import com.kichik.pecoff4j.util.Reflection;

public class GroupIconDirectory {
private int reserved;
private int type;
private int count;
private GroupIconDirectoryEntry[] entries;
private List<GroupIconDirectoryEntry> entries = new ArrayList<>();

public int getReserved() {
return reserved;
}

public void setReserved(int reserved) {
this.reserved = reserved;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public int getCount() {
return count;
return entries.size();
}

public GroupIconDirectoryEntry getEntry(int index) {
return entries[index];
return entries.get(index);
}

public List<GroupIconDirectoryEntry> getEntries() {
return entries;
}

@Override
Expand All @@ -50,12 +64,20 @@ public static GroupIconDirectory read(IDataReader dr) throws IOException {
GroupIconDirectory gi = new GroupIconDirectory();
gi.reserved = dr.readWord();
gi.type = dr.readWord();
gi.count = dr.readWord();
gi.entries = new GroupIconDirectoryEntry[gi.count];
for (int i = 0; i < gi.count; i++) {
gi.entries[i] = GroupIconDirectoryEntry.read(dr);
int count = dr.readWord();
for (int i = 0; i < count; i++) {
gi.entries.add(GroupIconDirectoryEntry.read(dr));
}

return gi;
}

public void write(IDataWriter dw) throws IOException {
dw.writeWord(reserved);
dw.writeWord(type);
dw.writeWord(entries.size());
for (GroupIconDirectoryEntry entry : entries) {
entry.write(dw);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;

import com.kichik.pecoff4j.io.IDataReader;
import com.kichik.pecoff4j.io.IDataWriter;
import com.kichik.pecoff4j.util.Reflection;

public class GroupIconDirectoryEntry {
Expand Down Expand Up @@ -48,35 +49,74 @@ public int getWidth() {
return width;
}

public int getHeight() {
public void setWidth(int width) {
this.width = width;
}

public int getHeight(){
return height;
}

public void setHeight(int height) {
this.height = height;
}

public int getColorCount() {
return colorCount;
}

public void setColorCount(int colorCount) {
this.colorCount = colorCount;
}

public int getReserved() {
return reserved;
}

public void setReserved(int reserved) {
this.reserved = reserved;
}

public int getPlanes() {
return planes;
}

public void setPlanes(int planes) {
this.planes = planes;
}

public int getBitCount() {
return bitCount;
}

public void setBitCount(int bitCount) {
this.bitCount = bitCount;
}

public int getBytesInRes() {
return bytesInRes;
}

public void setBytesInRes(int bytesInRes) {
this.bytesInRes = bytesInRes;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public void write(IDataWriter dw) throws IOException {
dw.writeByte(width);
dw.writeByte(height);
dw.writeByte(colorCount);
dw.writeByte(reserved);
dw.writeWord(planes);
dw.writeWord(bitCount);
dw.writeDoubleWord(bytesInRes);
dw.writeWord(id);
}
}

0 comments on commit 95bc3a8

Please sign in to comment.