<commit_before>// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <string>

#include "base/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/scoped_temp_dir.h"
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "include/cef_web_plugin.h"
#include "nw/client_handler.h"
#include "nw/client_switches.h"
#include "nw/common/zip.h"
#include "nw/nw.h"
#include "nw/string_util.h"
#include "nw/util.h"

#if defined(OS_WIN)
#include "base/string16.h"
#endif

namespace {

bool MakePathAbsolute(FilePath* file_path) {
  DCHECK(file_path);

  FilePath current_directory;
  if (!file_util::GetCurrentDirectory(&current_directory))
    return false;

  if (file_path->IsAbsolute())
    return true;

  if (current_directory.empty())
    return file_util::AbsolutePath(file_path);

  if (!current_directory.IsAbsolute())
    return false;

  *file_path = current_directory.Append(*file_path);
  return true;
}

void ManifestConvertRelativePaths(
    FilePath path,
    base::DictionaryValue* manifest) {
  if (manifest->HasKey(nw::kmMain)) {
    string16 out;
    if (!manifest->GetString(nw::kmMain, &out)) {
      manifest->Remove(nw::kmMain, NULL);
      LOG(WARNING) << "'main' field in manifest must be a string.";
      return;
    }

    FilePath main_path = path.Append(out);
    string16 url(L"file://");
    manifest->SetString(nw::kmMain, url + main_path.value());
  } else {
    LOG(WARNING) << "'main' field in manifest should be specifed.";
  }
}

bool ExtractPackage(const FilePath& zip_file, FilePath* where) {
  // Auto clean our temporary directory<commit_msg>Use string16 on Windows and std::string otherwise<commit_after>// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <string>

#include "base/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/scoped_temp_dir.h"
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "include/cef_web_plugin.h"
#include "nw/client_handler.h"
#include "nw/client_switches.h"
#include "nw/common/zip.h"
#include "nw/nw.h"
#include "nw/string_util.h"
#include "nw/util.h"

#if defined(OS_WIN)
#include "base/string16.h"
#endif

namespace {

bool MakePathAbsolute(FilePath* file_path) {
  DCHECK(file_path);

  FilePath current_directory;
  if (!file_util::GetCurrentDirectory(&current_directory))
    return false;

  if (file_path->IsAbsolute())
    return true;

  if (current_directory.empty())
    return file_util::AbsolutePath(file_path);

  if (!current_directory.IsAbsolute())
    return false;

  *file_path = current_directory.Append(*file_path);
  return true;
}

void ManifestConvertRelativePaths(
    FilePath path,
    base::DictionaryValue* manifest) {
  if (manifest->HasKey(nw::kmMain)) {
#if defined(OS_WIN)
    string16 out;
#else
    std::string out;
#endif
    if (!manifest->GetString(nw::kmMain, &out)) {
      manifest->Remove(nw::kmMain, NULL);
      LOG(WARNING) << "'main' field in manifest must be a string.";
      return;
    }

    FilePath main_path = path.Append(out);
#if defined(OS_WIN)
    string16 url(L"file://");
#else
    std::string url("file://");
#endif
    manifest->SetString(nw::kmMain, url + main_path.value());
  } else {
    LOG(WARNING) << "'main' field in manifest should be specifed.";
  }
}

bool ExtractPackage(const FilePath& zip_file, FilePath* where) {
  // Auto clean our temporary directory
{'fraction_non_alphanumeric': 0.1375648308224253, 'fraction_numerical': 0.005433440355643368, 'mean_word_length': 4.632823365785813, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6279186', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1360, 'n_words': 329}