greenworks icon indicating copy to clipboard operation
greenworks copied to clipboard

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

Open colining opened this issue 3 years ago • 5 comments

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 avatar Aug 13 '21 10:08 colining

@hokein

colining avatar Aug 13 '21 10:08 colining

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 avatar Aug 14 '21 07:08 colining

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 avatar Aug 16 '21 08:08 colining

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 avatar Oct 11 '21 09:10 colining

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 avatar Oct 11 '21 10:10 colining