Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【found solution】 Tags are not saved when publish or upload #296

Open
colining opened this issue Aug 13, 2021 · 5 comments
Open

【found solution】 Tags are not saved when publish or upload #296

colining opened this issue Aug 13, 2021 · 5 comments

Comments

@colining
Copy link

colining commented Aug 13, 2021

I want to publish tags with the workshop file, but it's not saved.

I look at the doc and find this function

greenworks.publishWorkshopFile = function(options, file_path, image_path, title,
    description, success_callback, error_callback) {}

so I just copy and modify like this

greenworks.ugcPublish = function(file_name, title, description, image_name,
    success_callback, error_callback, progress_callback) {
  var publish_file_process = function() {
    if (progress_callback)
      progress_callback("Completed on sharing files.");
    greenworks.publishWorkshopFile(file_name, image_name, title, description,
        function(publish_file_id) { success_callback(publish_file_id); },
        function(err) { error_process(err, error_callback); });
  };
  greenworks.saveFilesToCloud([file_name, image_name], function() {
    file_share_process(file_name, image_name, publish_file_process,
        error_callback, progress_callback);
  }, function(err) { error_process(err, error_callback); });
}

greenworks.ugcPublishWithTag = function(options, file_name, title, description, image_name,
                                 success_callback, error_callback, progress_callback) {
  var publish_file_process = function() {
    if (progress_callback)
      progress_callback("Completed on sharing files.");
    greenworks.publishWorkshopFile(options,file_name, image_name, title, description,
      function(publish_file_id) { success_callback(publish_file_id); },
      function(err) { error_process(err, error_callback); });
  };
  greenworks.saveFilesToCloud([file_name, image_name], function() {
    file_share_process(file_name, image_name, publish_file_process,
      error_callback, progress_callback);
  }, function(err) { error_process(err, error_callback); });
}

but sadly the tags are not saved

any idea?

@colining
Copy link
Author

@hokein

@colining
Copy link
Author

colining commented Aug 14, 2021

I'm not familiar with c++, but I think it may be a cast error?
tags.m_ppStrings = reinterpret_cast<const char**>(&properties_.tags);
@benaadams @MikalDev

@colining
Copy link
Author

colining commented Aug 16, 2021

I'm trying to log tags.m_ppStrings and it's empty

  tags.m_nNumStrings = properties_.tags_scratch.size();
  tags.m_ppStrings = reinterpret_cast<const char**>(&properties_.tags);
  printf(tags.m_ppStrings[0])

and then I found the log of greenworks/src/api/steam_api_workshop.cc

And there are some commit look like have effect with tags

@colining
Copy link
Author

colining commented Oct 11, 2021

Two months later, no one replay so I learned C++. And found there are two bugs need fix;

No.1 steam_api_workshop.cc line 165

  for (uint32_t i = 0; i < tags_array->Length(); ++i) {
    if (!Nan::Get(tags_array, i).ToLocalChecked()->IsString())
      THROW_BAD_ARGS("Bad arguments");
    Nan::Utf8String tag(Nan::Get(tags_array, (i)).ToLocalChecked());
    properties.tags_scratch.push_back(*tag);
    properties.tags[i] = properties.tags_scratch.back().c_str();   // this line create the bug
  }

I try like this:

    const char *a[4] = { "Blue", "Red",
                              "Orange", "Yellow" };
    const char* tags[MAX_TAGS];
    const char **p = new const char *[10];
    vector<string> tags_scratch;

    for (int i = 0; i < 4; ++i) {
        cout << a[i] << endl;
        tags_scratch.push_back(a[i]);
        tags[i] = tags_scratch.back().c_str();
    }
    for (int i = 0; i < 4; ++i) {
        cout << tags_scratch[i] << "\t";
        cout << tags[i];
        cout << endl;
    }

and the cout is like this:

Blue
Red
Orange
Yellow
Blue    葺葺葺葺葺葺葺葺葺葺葺葺葺葺�?6;�
Red     葺葺葺葺葺葺葺葺葺葺葺葺葺葺葺葺╗
Orange  葺葺葺葺葺葺葺葺葺葺葺葺葺葺╗
Yellow  Yellow

change the code like this will fix this bug

    for (int i = 0; i < 4; ++i) {
        cout << a[i] << endl;
        tags_scratch.push_back(a[i]);
        tags[i] = tags_scratch.back().c_str();
    }
   for (int i = 0; i < tags_scratch.size(); ++i) {
        tags[i] = tags_scratch[i].c_str();
    }

No.2 greenworks_workshop_workers.cc line 154
try add a cout

    cout << properties_.tags << endl;
    for(int tag = 0; tag < 1; ++tag)
    {
        cout << properties_.tags[tag] << ":\t";
    }

and the cout result is like this

00000207F1BA4908
:    //nothing but  ":"

I'm not sure about what makes the PublishWorkshopFileWorker::Execute run

seems related to Nan::AsyncWorker , but I'm not familiar with c++ or Nan

but it seems there is something error when AsyncWorker call the Execute and pass the value;

@colining
Copy link
Author

colining commented Oct 11, 2021

And now my solution is like this
greenworks_workshop_workers.cc line 154

    // tags.m_ppStrings = reinterpret_cast<const char**>(&properties_.tags); replace this line as the flowing
    tags.m_ppStrings = new const char *[tags.m_nNumStrings];
    for (int i = 0; i < tags.m_nNumStrings; ++i) {
        tags.m_ppStrings[i] = properties_.tags_scratch[i].c_str();
    }

It's a pity that no one maintains this project。

hope useful for you

@colining colining changed the title Tags are not saved when publish or upload [found solution]Tags are not saved when publish or upload Oct 11, 2021
@colining colining changed the title [found solution]Tags are not saved when publish or upload 【found solution】 Tags are not saved when publish or upload Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant