Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
m35 committed Jul 10, 2024
1 parent 04270fd commit db0320e
Show file tree
Hide file tree
Showing 34 changed files with 28,241 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.java text diff=java
*.properties text
*.xml text
*.ini text
*.md text
*.txt text
*.form text eol=lf

*.class binary
*.jar binary
*.png binary
*.ico binary
*.xcf binary
Binary file added .github/BupV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/Unity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/tar-directories.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/tar-directory-contents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target/
/.idea/
/nbactions.xml
/history.ini
/dependency-reduced-pom.xml
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Disclaimer

This is a hobby project. I work on it for fun.
If I'm not having fun, I probably won't do it :)
You're welcome to report issues, or create pull requests.
But if they're not useful to me, I probably won't respond
(though they may help others who run into them).
If you really want to see enhancements, fork it and have fun. :)

# Development environment

Any Java IDE of your choice. However the main window form was creating using Netbeans form designer, so you'll want that to edit the GUI.

# Building

It's a standard Maven project. Run
```
mvn clean install
```
It will generate a self-contained fat jar in the `/target/` directory that is ready to use.

# Reporting issues

Use issue reporting best practices. Provide these 3 things:

1. Steps to reproduce the issue
2. Expected behavior
3. Actual behavior

# Pull requests

Check your code against SpotBugs, PMD, or IntelliJ inspections. Fix any issues.

Anything that is merged will be a fast-forward or squash-merge.
661 changes: 661 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Basic .unitypackage Viewer

I just wanted a simple tool to do the following:

* Browse the tree of a `.unitypackage` file
* Extract some individual files
* All without having to start Unity

So I threw this together for my own use. Maybe it could be helpful to others.

This is a Java program requiring Java 8 or higher.


# How to use

![](.github/BupV.png?raw=true)

* Run with Java
* Accepts a `.unitypackage` as a program argument to open immediately
* Open `.unitypackage` files using the Open button, or drag and drop a `.unitypackage` onto the window
* Search by name or GUID in the text box and press Enter or the Search button
* Expand/Collapse the tree
* Files with a preview will appear in the preview box
* Extract the selected item into the same directory as the `.unitypackage`.
The directory will be opened in your OS file viewer.
* Right-click to copy name, size, or GUID
* History.ini saves the last directory used


# Disclaimers

* This is *beta* quality software. No rigorous testing has been done. It probably has bugs. Only tested with data as I make use of it.

* All I know about the `.unitypackage` file format came from examining several files, and reading code from some existing tools.
I didn't read any specification (assuming there is one). There could certainly be edge cases this misses.

# The `.unitypackage` file format

A `.unitypackage` is just a compressed TAR archive.
Inside it contains several root directories.
Each directory name is a GUID.

![](.github/tar-directories.png?raw=true)


Inside each of them is the contents of the asset with that GUID.
Specifically, each GUID directory contains some of these 4 files.

![](.github/tar-directory-contents.png?raw=true)

* `pathname` First line of text is the full path of the asset where it will appear when imported into Unity.
* `asset.meta` The corresponding .meta file.
* `asset` Contains the actual asset payload. Won't exist for directories.
* `preview.png` Optional preview of some types of assets.


It's not difficult to build up the structure of what's shown when you import into unity.

As shown in Unity:

![](.github/Unity.png?raw=true)

As shown in this tool:

![](.github/BupV.png?raw=true)

# Existing open source tools I found

### https://gist.github.com/yasirkula/dfc43134fbfefb820d0adbc5d7c25fb3

A very nice Unity script to explore `.unitypackages`.

### https://github.com/Switch-9867/UnitypackgeExtractor

C# command-line tool.

### https://github.com/Cobertos/unitypackage_extractor

Python command-line tool. Its associated pypi package at https://pypi.org/project/unitypackage-extractor/

Binary file added icon/1033_Icon_103.ico
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/BupVIcon.ico
Binary file not shown.
Binary file added icon/BupVIcon.xcf
Binary file not shown.
80 changes: 80 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>m35-projects</groupId>
<artifactId>unity-package-viewer</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.2</version>
</dependency>
</dependencies>

<build>
<resources>
<resource><directory>src/main/resources</directory></resource>
<resource><directory>src/main/java</directory></resource>
<resource>
<directory>src/main/misc</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>.</directory>
<includes><include>LICENSE.txt</include></includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>UnityPackageViewer-${project.version}</finalName>
<minimizeJar>true</minimizeJar>

<!-- Choose my MANIFEST.MF as the winner -->
<filters>
<filter>
<artifact>${project.groupId}:${project.artifactId}</artifact>
<includes>
<include>**/*</include>
</includes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>

<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>unitypackage.viewer.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
86 changes: 86 additions & 0 deletions src/main/java/unitypackage/model/UnityAsset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Basic .unitypackage Viewer
* Copyright (C) 2024 Michael Sabin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package unitypackage.model;

import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;

/**
* An asset as it would appear in the tree of stuff you see when you import a .unitypackage into unity.
* This could be a directory or a file.
*/
public class UnityAsset {

private final UnityAssetBuilder source;

UnityAsset(UnityAssetBuilder source) {
this.source = source;
}

public String getFullPath() {
return source.getPathname_firstLine();
}

public Path getFullPathAsPath() {
return Paths.get(getFullPath());
}

public Path getFileNameAsPath() {
return getFullPathAsPath().getFileName();
}

public String getFileName() {
return getFileNameAsPath().toString();
}

public long getSize() {
return source.getAsset_fileSize();
}

public String getGuid() {
return source.getAsset_meta_guid();
}

public String getDirectoryGuid() {
return source.getGuidBaseDirectory();
}

public BufferedImage getPreview() {
return source.getPreview();
}

public boolean isProbablyDirectory() {
return source.getRawPathTo_asset_file() == null;
}

String getTarPathOf_asset_File() {
return source.getRawPathTo_asset_file();
}

public Date getDateModified() {
return source.getAsset_dateModified();
}

@Override
public String toString() {
return "UnityAsset{" + getFullPath() + '}';
}
}
Loading

0 comments on commit db0320e

Please sign in to comment.