Ejemplo n.º 1
0
void ParseAsync(const Nan::FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  int args_length = args.Length();

  if (args_length < 2) {
    isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
    return;
  }

  Local<Value> input = args[0];
  if (!ValidateInput(input, isolate)) {
    return;
  }
  if (!args[1]->IsFunction()) {
    isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second parameter must be a callback")));
    return;
  }

  Nan::Callback *callback = new Nan::Callback(args[1].As<Function>());
  anitomyJs::Worker *worker = new anitomyJs::Worker(callback);

  if (args_length >= 3) {
    Local<Value> options = args[2];
    if (!ValidateOptions(options, isolate) ||
        !worker->GetAnitomy()->SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
      return;
    }
  }

  worker->GetAnitomy()->SetInput(input, isolate);
  Nan::AsyncQueueWorker(worker);
  args.GetReturnValue().Set(Nan::Undefined());
}
Ejemplo n.º 2
0
void ParseSync(const Nan::FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  int args_length = args.Length();

  if (args_length < 1) {
    isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
    return;
  }

  Local<Value> input = args[0];
  if (!ValidateInput(input, isolate)) {
    return;
  }

  anitomyJs::AnitomyJs anitomy;
  if (args_length >= 2) {
    Local<Value> options = args[1];
    if (!ValidateOptions(options, isolate) ||
        !anitomy.SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
      return;
    }
  }

  anitomy.SetInput(input, isolate);
  anitomy.Parse();

  args.GetReturnValue().Set(anitomy.ParsedResult(isolate));
}
Ejemplo n.º 3
0
/* Get version
 *
 * Get the version of the application based on hard-coded value above.
 * @return (string) Version
 */
void nodeGetVersion(const Nan::FunctionCallbackInfo<v8::Value> &args) {
    // Allocate a new scope when we create v8 JavaScript objects.
    v8::Isolate *isolate = args.GetIsolate();
    Nan::HandleScope scope;

    // Convert to v8 String
    v8::Handle<v8::String> result = v8::String::NewFromUtf8(isolate, version.c_str());

    // Ship it out...
    args.GetReturnValue().Set(result);
    return;
}
Ejemplo n.º 4
0
/* Extract files into directory.
 *
 * Extract an array of files (args[0]) into a directory of choice (args[1]).
 * @param (string) Source directory of CASC archive
 * @param (string) Destination directory to extract files
 * @param (array) Array of files within the CASC archive
 * @return (int) Number of files successfully extracted.
 */
void nodeExtractFiles(const Nan::FunctionCallbackInfo<v8::Value> &args) {
    // Allocate a new scope when we create v8 JavaScript objects.
    v8::Isolate *isolate = args.GetIsolate();
    Nan::HandleScope scope;

    // strSource
    strSource = *v8::String::Utf8Value(args[0]->ToString());
    if ((strSource[strSource.size() - 1] == '/') || (strSource[strSource.size() - 1] == '\\'))
        strSource = strSource.substr(0, strSource.size() - 1);

    // strDestination
    strDestination = *v8::String::Utf8Value(args[1]->ToString());
    if (strDestination.at(strDestination.size() - 1) != '/')
        strDestination += "/";

    // Open CASC archive
    if (!CascOpenStorage(strSource.c_str(), 0, &hStorage)) {
        cerr << "Failed to open the storage '" << strSource << "'" << endl;
        args.GetReturnValue().Set(-1);
        return;
    }

    int filesDone = 0;

    if (args[2]->IsArray()) {
        v8::Handle<v8::Array> files = v8::Handle<v8::Array>::Cast(args[2]);
        for (uint32_t i = 0; i < files->Length(); i++) {
            v8::String::Utf8Value item(files->Get(i)->ToString());
            std::basic_string<char> file = std::string(*item);
            size_t bytesWritten = extractFile(file);
            if (bytesWritten > 0) {
              filesDone++;
            }
        }
    }

    // Clean it up...
    CascCloseStorage(hStorage);
    hStorage = NULL;

    // Ship it out...
    args.GetReturnValue().Set(filesDone);
    return;
}
Ejemplo n.º 5
0
/* List all files in a CASC archive.
 *
 * @param (string) Source directory of CASC files
 * @return (array) Full paths of files in the archive
 */
void nodeListFiles(const Nan::FunctionCallbackInfo<v8::Value> &args) {
    // Set API variables
    bQuiet = true;
    bVerbose = false;

    // Allocate a new scope when we create v8 JavaScript objects.
    v8::Isolate *isolate = args.GetIsolate();
    Nan::HandleScope scope;

    strSource = *v8::String::Utf8Value(args[0]->ToString());

    if ((strSource[strSource.size() - 1] == '/') || (strSource[strSource.size() - 1] == '\\'))
        strSource = strSource.substr(0, strSource.size() - 1);

    if (!CascOpenStorage(strSource.c_str(), 0, &hStorage)) {
        cerr << "Failed to open the storage '" << strSource << "'" << endl;
        return;
    }

    // Define variables
    CASC_FIND_DATA findData;
    HANDLE handle = CascFindFirstFile(hStorage, "*", &findData, NULL);

    // Let's get this party started..
    vector<string> results = searchArchive();

    // Convert returned vector of *chars to a v8::Array of v8::Strings
    v8::Handle<v8::Array> files = v8::Array::New(isolate);
    for (unsigned int i = 0; i < results.size(); i++ ) {
      v8::Handle<v8::String> result = v8::String::NewFromUtf8(isolate, results[i].c_str());
      files->Set(i, result);
    }

    // Clean it up...
    CascFindClose(handle);
    CascCloseStorage(hStorage);
    handle = NULL;
    hStorage = NULL;

    // Ship it out...
    args.GetReturnValue().Set(files);
    return;
}