code-disaster / steamworks4j

A thin Java wrapper to access the Steamworks API
https://code-disaster.github.io/steamworks4j/
MIT License
468 stars 64 forks source link

Steam Workshop Uploader #96

Closed Superwutz closed 2 years ago

Superwutz commented 4 years ago

Hi guys,

did anyone ever use this for a Steamworkshop implementation?

I am trying my best to do so, creating a new workshop item does work fine but as soon as I populate it with content and try to submit it, its fails giving back FAIL as result..

here is my function:

public void upload(SteamPublishedFileID fileID, String modPath, String tumbnail, int visibility, String title, String desc,
            String changenote) {

        lastItemID = null;
        lastItemResult = null;
        submitted = false;
        if(fileID==null) {
            ugc.createItem(appID, SteamRemoteStorage.WorkshopFileType.Community);
            long now = System.currentTimeMillis();
            while (lastItemID == null || lastItemResult == null) {
                SteamAPI.runCallbacks();
                System.out.println("creating..");
                if (System.currentTimeMillis() - now > 100000) {
                    onFailure();
                    System.out.println("Timed out!");
                    return;
                }try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
            if (lastItemResult == null || !lastItemResult.toString().equals("OK")) {
                onFailure();
                return;
            }
        }else
            lastItemID=fileID;
        SteamUGCUpdateHandle update;
        System.out.println("Starting update");
        update = ugc.startItemUpdate(appID, lastItemID);

        if (modPath != null) {
            ugc.setItemContent(update, modPath);
            System.out.println("Modpath set to: "+modPath);
        }

        if (tumbnail != null) {
            ugc.setItemPreview(update, tumbnail);
            System.out.println("Tumbnailpath set to: "+tumbnail);
        }

        if (visibility == 2) {
            SteamRemoteStorage.PublishedFileVisibility rsVisibility;
            rsVisibility = SteamRemoteStorage.PublishedFileVisibility.Public;
            ugc.setItemVisibility(update, rsVisibility);
        } else if (visibility == 1) {
            SteamRemoteStorage.PublishedFileVisibility rsVisibility;
            rsVisibility = SteamRemoteStorage.PublishedFileVisibility.FriendsOnly;
            ugc.setItemVisibility(update, rsVisibility);
        } else if (visibility == 0) {
            SteamRemoteStorage.PublishedFileVisibility rsVisibility;
            rsVisibility = SteamRemoteStorage.PublishedFileVisibility.Private;
            ugc.setItemVisibility(update, rsVisibility);
        }

        if (title != null) {
            ugc.setItemTitle(update, title);
            System.out.println("Title set to: "+title);
        }

        if (desc != null) {
            ugc.setItemDescription(update, desc);
            System.out.println("Description set to: "+desc);
        }
        ItemUpdateInfo updateInfo = new ItemUpdateInfo();
        ugc.submitItemUpdate(update, changenote);
        ugc.getItemUpdateProgress(update, updateInfo);
        System.out.println("Submitting update.."+updateInfo.getBytesProcessed()+"/"+updateInfo.getBytesTotal());
        long now = System.currentTimeMillis();
        while (!submitted) {
            SteamAPI.runCallbacks();
            ugc.getItemUpdateProgress(update, updateInfo);
            System.out.println("Submitting..");
            System.out.println("Progress: "+updateInfo.getBytesProcessed()+"/"+updateInfo.getBytesTotal());
            if (System.currentTimeMillis() - now > 100000) {
                onFailure();
                System.out.println("Timed out!");
                return;
            }try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        ugc.dispose();

        // c.dispose();

    }
N00ree commented 2 years ago

I also had this error once.

According to the Steam docs, you can also take a look at the following log files:

Steam\logs\Workshop_log.txt and Steam\workshopbuilds\depotbuild.log where Steam is the Steam installation directory (e.g., D:\Program Files (x86)\Steam)

In my case, the depotbuild.log helped a lot. The log file contained this:

[2021-11-29 04:37:11]: Building file listing for depot <Your game app id>... [2021-11-29 04:37:11]: Found 0 files for mapping: Waving -> . [2021-11-29 04:37:11]: ERROR! Build for workshop item has no content [2021-11-29 04:37:11]: ERROR! Failed building file list

This obviously means the path to the content folder (used in setItemContent) is incorrect.

I hope this helps.

code-disaster commented 2 years ago

Note that getItemUpdateProgress() is for consuming items, so to check while a user is downloading a workshop item. For submitItemUpdate(), you are supposed to wait for the onSubmitItemUpdate() callback.

The code above fails because this callback isn't checked, while the loop is waiting for a update progress which doesn't exist.