Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
default_stages: [ pre-push ]
fail_fast: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
args: [ --markdown-linebreak-ext=md ]
- id: end-of-file-fixer
- id: check-yaml
- id: mixed-line-ending
- id: check-merge-conflict
- id: detect-private-key
- id: check-yaml
- id: check-toml
- id: check-json
- id: check-docstring-first
- id: check-added-large-files
args: [ '--maxkb=600' ]
args: [ --maxkb=500 ]
- id: pretty-format-json
args: [ --autofix, --no-sort-keys ]

- repo: local
hooks:
Expand All @@ -16,18 +27,17 @@ repos:
entry: make format
language: system
pass_filenames: false
types: [ java ]
stages: [ pre-commit ]

- id: lint
name: Check code style
name: Run the linter checks
entry: make lint
language: system
pass_filenames: false
types: [ java ]
stages: [ pre-commit ]

- id: test
name: Run tests
name: Run the tests
entry: make test
language: system
pass_filenames: false
stages: [ pre-commit ]
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ clean: ## Remove all build artifacts
@echo "Cleaning project..."
@$(MVN) -B clean

setup-hooks: ## Set up pre-commit hooks
@echo "Setting up pre-commit hooks..."
setup-hooks: ## Install Git hooks (pre-commit and pre-push)
@echo "Setting up Git hooks..."
@if ! command -v pre-commit &> /dev/null; then \
echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \
exit 1; \
fi
@pre-commit install --install-hooks
@pre-commit install --hook-type pre-commit
@pre-commit install --hook-type pre-push
@pre-commit install-hooks

test-hooks: ## Test pre-commit hooks on all files
@echo "Testing pre-commit hooks..."
@./scripts/test-pre-commit.sh
test-hooks: ## Test Git hooks on all files
@echo "Testing Git hooks..."
@pre-commit run --all-files --show-diff-on-failure
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
[![Code Quality](https://img.shields.io/codefactor/grade/github/pixel-clover/uview?label=quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/pixel-clover/uview)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue?style=flat&labelColor=282c34&logo=open-source-initiative)](LICENSE)
[![Release](https://img.shields.io/github/release/pixel-clover/uview.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/pixel-clover/uview/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/pixel-clover/uview/total?label=downloads&style=flat&labelColor=282c34&logo=github)](https://github.com/pixel-clover/uview/releases)

A cross-platform tool for viewing and modifying Unity package files

Expand Down Expand Up @@ -93,4 +92,4 @@ Box logo is from [SVG Repo](https://www.svgrepo.com/svg/366323/package-inspect).

### License

UView is available under the Apache License, Version 2.0 ([LICENSE](LICENSE)).
UView is available under the Apache License, Version 2.0 (see [LICENSE](LICENSE)).
29 changes: 28 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.pixelclover.uview</groupId>
<artifactId>uview</artifactId>
<version>0.1.0-b.2</version>
<version>0.1.0</version>
<packaging>jar</packaging>

<name>UView</name>
Expand All @@ -18,6 +18,7 @@
<java.version>21</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>

<javafx.version>21.0.2</javafx.version>
<flatlaf.version>3.4.1</flatlaf.version>
<commons.compress.version>1.26.2</commons.compress.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
Expand Down Expand Up @@ -101,6 +102,16 @@
<artifactId>imageio-tiff</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tga</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
Expand All @@ -116,6 +127,21 @@
<artifactId>vorbisspi</artifactId>
<version>1.0.3.3</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>${javafx.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -183,6 +209,7 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.github.pixelclover.uview.App</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
Expand Down
24 changes: 0 additions & 24 deletions scripts/test-pre-commit.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/io/github/pixelclover/uview/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.formdev.flatlaf.extras.FlatUIDefaultsInspector;
import io.github.pixelclover.uview.gui.FontManager;
import io.github.pixelclover.uview.gui.MainWindow;
import javax.swing.*;
import javax.swing.SwingUtilities;

/** The main entry point for the UView application. */
public final class App {
Expand Down
32 changes: 22 additions & 10 deletions src/main/java/io/github/pixelclover/uview/core/PackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@
*/
public class PackageManager {
private static final Logger LOGGER = LogManager.getLogger(PackageManager.class);
private static final long MAX_ASSET_SIZE_BYTES = 512 * 1024 * 1024; // 512 MB limit
private final PackageIO packageIO;
private static final long DEFAULT_MAX_ASSET_SIZE_BYTES = 512 * 1024 * 1024; // 512 MB limit
private final PackageIO packageIo;
private final long maxAssetSizeBytes;
private UnityPackage activePackage = new UnityPackage();
private boolean isModified = false;

/**
* Constructs a PackageManager with a given PackageIO handler.
* Constructs a PackageManager with a given PackageIO handler and default max asset size.
*
* @param packageIO The I/O handler for reading and writing package files.
* @param packageIo The I/O handler for reading and writing package files.
*/
public PackageManager(PackageIO packageIO) {
this.packageIO = packageIO;
public PackageManager(PackageIO packageIo) {
this(packageIo, DEFAULT_MAX_ASSET_SIZE_BYTES);
}

/**
* Constructs a PackageManager with a given PackageIO handler and a custom max asset size.
*
* @param packageIo The I/O handler for reading and writing package files.
* @param maxAssetSizeBytes The maximum allowed size for an asset in bytes.
*/
public PackageManager(PackageIO packageIo, long maxAssetSizeBytes) {
this.packageIo = packageIo;
this.maxAssetSizeBytes = maxAssetSizeBytes;
}

/** Creates a new, empty package, discarding any existing active package data. */
Expand All @@ -47,7 +59,7 @@ public void createNew() {
* @throws IOException If an error occurs during file loading.
*/
public void loadPackage(File packageFile) throws IOException {
activePackage = packageIO.load(packageFile);
activePackage = packageIo.load(packageFile);
isModified = false;
LOGGER.info("Loaded package: {}", packageFile.getAbsolutePath());
}
Expand All @@ -59,7 +71,7 @@ public void loadPackage(File packageFile) throws IOException {
* @throws IOException If an error occurs during file saving.
*/
public void savePackage(File packageFile) throws IOException {
packageIO.save(activePackage, packageFile);
packageIo.save(activePackage, packageFile);
isModified = false;
LOGGER.info("Saved package: {}", packageFile.getAbsolutePath());
}
Expand Down Expand Up @@ -110,11 +122,11 @@ public Collection<UnityAsset> getAssetsUnderPath(String pathPrefix) {
* @throws IOException If the file is too large or cannot be read.
*/
public void addAsset(Path sourceFile, String assetPath) throws IOException {
if (Files.size(sourceFile) > MAX_ASSET_SIZE_BYTES) {
if (Files.size(sourceFile) > maxAssetSizeBytes) {
throw new IOException(
String.format(
"File is too large (%.1f MB). Maximum allowed size is %d MB.",
Files.size(sourceFile) / (1024.0 * 1024.0), MAX_ASSET_SIZE_BYTES / (1024 * 1024)));
Files.size(sourceFile) / (1024.0 * 1024.0), maxAssetSizeBytes / (1024 * 1024)));
}
byte[] content = Files.readAllBytes(sourceFile);
String metaGuid = java.util.UUID.randomUUID().toString().replace("-", "");
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/io/github/pixelclover/uview/core/SettingsManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.pixelclover.uview.core;

import io.github.pixelclover.uview.App;
import java.awt.*;
import java.awt.Font;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,7 +18,11 @@ public class SettingsManager {
private static final String LAST_DIRECTORY_KEY = "last_directory";
private static final String RECENT_FILE_PREFIX = "recent_file_";

private static final String THEME_IS_DARK_KEY = "theme_is_dark";
private static final String THEME_KEY = "theme";
public static final String THEME_LIGHT = "Light";
public static final String THEME_DARK = "Dark";
public static final String THEME_SYSTEM = "System";

private static final String FONT_SIZE_KEY = "font_size";
private static final String FONT_FAMILY_KEY = "font_family";
private static final int DEFAULT_FONT_SIZE = 12;
Expand All @@ -41,21 +45,21 @@ public SettingsManager(Preferences prefs) {
}

/**
* Checks if the dark theme is currently enabled.
* Gets the current theme.
*
* @return true if dark theme is set, false otherwise.
* @return The current theme, e.g., "Light", "Dark", or "System".
*/
public boolean isDarkTheme() {
return prefs.getBoolean(THEME_IS_DARK_KEY, false);
public String getTheme() {
return prefs.get(THEME_KEY, THEME_SYSTEM);
}

/**
* Sets the theme preference.
*
* @param isDark true to enable dark theme, false for light theme.
* @param theme The theme to set, e.g., "Light", "Dark", or "System".
*/
public void setDarkTheme(boolean isDark) {
prefs.putBoolean(THEME_IS_DARK_KEY, isDark);
public void setTheme(String theme) {
prefs.put(THEME_KEY, theme);
}

/**
Expand Down Expand Up @@ -96,7 +100,9 @@ public void setFontFamily(String fontFamily) {

/** Resets all UI-related settings (theme and font) to their default states. */
public void resetUiSettings() {
prefs.remove(THEME_IS_DARK_KEY);
prefs.remove(THEME_KEY);
// For backward compatibility, remove the old key
prefs.remove("theme_is_dark");
prefs.remove(FONT_SIZE_KEY);
prefs.remove(FONT_FAMILY_KEY);
}
Expand Down
Loading
Loading