Browse Source

Minor refinements

tags/0.1.0
Jake Wakeling 4 months ago
parent
commit
a47f727e91
5 changed files with 22 additions and 32 deletions
  1. 0
    6
      CMakeLists.txt
  2. 1
    1
      LICENCE
  3. 2
    2
      include/liboar.h
  4. 14
    12
      src/liboar/oar.c
  5. 5
    11
      src/liboar/oar.h

+ 0
- 6
CMakeLists.txt View File

@@ -6,14 +6,8 @@ set(CMAKE_C_STANDARD 11) # C Standard

# Output Directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") # Linux Specific CMake Variables
set(LINK_DIR /lib/x64/) # Standard Linux Library Directory

+ 1
- 1
LICENCE View File

@@ -1,7 +1,7 @@
OMKOV Open Source Licence 1.1
Based on the UIUC Licence

Copyright (c) 2019, Jakob Wakeling
Copyright (C) 2019, Jakob Wakeling
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of

+ 2
- 2
include/liboar.h View File

@@ -1,6 +1,6 @@
// liboar.h
// Public header file for OmegaARc
// Copyright (c) 2019, Jakob Wakeling
// Copyright (C) 2019, Jakob Wakeling
// All rights reserved.

#ifndef LIBOAR_H
@@ -12,7 +12,7 @@
extern "C" {
#endif

int oarCompress(char *oarPath, int fileCount, char *fileName[]);
int oarCompress(char *oarPath, size_t fileCount, char *fileName[]);
int oarExtract(char *oarPath, char *extractPath);

#ifdef __cplusplus

+ 14
- 12
src/liboar/oar.c View File

@@ -1,6 +1,6 @@
// oar.c
// Main source file for OmegaARc
// Copyright (c) 2019, Jakob Wakeling
// Copyright (C) 2019, Jakob Wakeling
// All rights reserved.

#define _CRT_SECURE_NO_WARNINGS
@@ -15,7 +15,7 @@

// Compress files into OmegaARc archive
// 0x0A10: Failed to open archive file for writing
int oarCompress(char *oarPath, int fileCount , char *filename[]) {
int oarCompress(char *oarPath, size_t fileCount , char *filename[]) {
FILE *oarFile = fopen(oarPath, "wb"); // Open OAR archive for writing
if (oarFile == NULL) {
fprintf(stderr, "OARx0A10: Failed to open %s for writing\n", oarPath);
@@ -69,7 +69,7 @@ int oarExtract(char *oarPath, char *extractPath) {
// 0x0A11: Failed to open input file
int fileAdd(FILE *oarFile, char *file, char *filename) {
size_t index = ftell(oarFile); // Get current file index
fileExpand(oarFile, OAR_H_SIZE, 0); // Expand file by header size
fileExpand(oarFile, OAR_H_SIZE, 0x00); // Expand file by header size

FILE *input = fopen(file, "rb"); // Open input file
if (input == NULL) { // Check that file is open
@@ -78,19 +78,23 @@ int fileAdd(FILE *oarFile, char *file, char *filename) {
}

while (!feof(input)) { // Read input file into OAR archive
char buffer[2048]; // Copy file in 2048 byte segments
uint64_t read = fread(buffer, 1, 2048, input);
byte_t *buffer = malloc(2048); // Copy file in 2048 byte segments

size_t read = fread(buffer, 1, 2048, input);
fwrite(buffer, 1, read, oarFile);

free(buffer);
buffer = NULL;
}
size_t end = ftell(oarFile); // Store end of file index

oarHeader header; // Declare OAR header
memset(&header, 0, OAR_H_SIZE); // Clear header
snprintf(header.name, 96, "%s", filename);
snprintf(header.size, 24, "%023d", (uint)end - OAR_H_SIZE - (uint)index);
snprintf(header.size, 24, "%023d", (uint_t)end - OAR_H_SIZE - (uint_t)index);

uint checksum = 0;
const uint *bytes = &header;
uint_t checksum = 0;
const uint_t *bytes = &header;
for (int i = 0; i < OAR_H_SIZE; ++i) {
checksum += bytes[i]; // Generate file checksum
}
@@ -108,7 +112,7 @@ int fileAdd(FILE *oarFile, char *file, char *filename) {

// Decode file header
// TODO: Implement error checking for header decode
oarHeader fileDecode(FILE *oarFile, uint headerSize) {
oarHeader fileDecode(FILE *oarFile, size_t headerSize) {
oarHeader header; // Declare OAR header
memset(&header, 0, OAR_H_SIZE); // Clear header

@@ -125,8 +129,7 @@ oarHeader fileDecode(FILE *oarFile, uint headerSize) {
int fileExtract(FILE *oarFile, char *file, int fileSize) {
FILE *outputFile = fopen(file, "wb");
if (outputFile == NULL) {
fprintf(stderr, "OARx0A22: Failed to open %s for writing\n",
outputFile);
fprintf(stderr, "OARx0A22: Failed to open %s for writing\n", file);
return 0x0A22;
}

@@ -166,6 +169,5 @@ void WriteSignature(FILE *oarFile) {
uint32_t headerVersion = OAR_H_VERSION; // Load OAR header version
headerVersion = swap32(headerVersion);
fwrite(&headerVersion, 4, 1, oarFile); // Write signature to OAR archive

return;
}

+ 5
- 11
src/liboar/oar.h View File

@@ -1,19 +1,16 @@
// oar.h
// Main header file for OmegaARc
// Copyright (c) 2019, Jakob Wakeling
// Copyright (C) 2019, Jakob Wakeling
// All rights reserved.

#ifndef OAR_H
#define OAR_H

#define uint unsigned int

#define OAR_H_VERSION 0x4F415200
#define OAR_H_SIZE 128

#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned char byte_t;
typedef unsigned int uint_t;

typedef struct oarHeader { // OmegaARc Header (128 Bytes)
char name[96]; // File Name (96 Bytes)
@@ -21,17 +18,14 @@ typedef struct oarHeader { // OmegaARc Header (128 Bytes)
char checksum[8]; // Header Checksum (8 Bytes)
} oarHeader;

int oarCompress(char *oarPath, int fileCount, char *fileName[]);
int oarCompress(char *oarPath, size_t fileCount, char *fileName[]);
int oarExtract(char *oarPath, char *extractPath);

int fileAdd(FILE *oarFile, char *file, char *fileName);
oarHeader fileDecode(FILE *oarFile, uint headerSize);
oarHeader fileDecode(FILE *oarFile, size_t headerSize);
int fileExtract(FILE *oarFile, char *file, int fileSize);
int fileExpand(FILE *oarFile, int amount, char value);

void WriteSignature(FILE *oarFile);

#ifdef __cplusplus
}
#endif
#endif // OAR_H

Loading…
Cancel
Save