Exemplo n.º 1
0
Arquivo: vdr.c Projeto: chouquette/vlc
/*****************************************************************************
 * Open a directory
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    access_t *p_access = (access_t*)p_this;

    if( !p_access->psz_filepath )
        return VLC_EGENERIC;

    /* Some tests can be skipped if this module was explicitly requested.
     * That way, the user can play "corrupt" recordings if necessary
     * and we can avoid false positives in the general case. */
    bool b_strict = strcmp( p_access->psz_name, "vdr" );

    /* Do a quick test based on the directory name to see if this
     * directory might contain a VDR recording. We can be reasonably
     * sure if ScanDirectory() actually finds files. */
    if( b_strict )
    {
        char psz_extension[4];
        int i_length = 0;
        const char *psz_name = BaseName( p_access->psz_filepath );
        if( sscanf( psz_name, "%*u-%*u-%*u.%*u.%*u.%*u%*[-.]%*u.%3s%n",
            psz_extension, &i_length ) != 1 || strcasecmp( psz_extension, "rec" ) ||
            ( psz_name[i_length] != DIR_SEP_CHAR && psz_name[i_length] != '\0' ) )
            return VLC_EGENERIC;
    }

    /* Only directories can be recordings */
    struct stat st;
    if( vlc_stat( p_access->psz_filepath, &st ) ||
        !S_ISDIR( st.st_mode ) )
        return VLC_EGENERIC;

    access_sys_t *p_sys = vlc_calloc( p_this, 1, sizeof( *p_sys ) );

    if( unlikely(p_sys == NULL) )
        return VLC_ENOMEM;

    p_access->p_sys = p_sys;
    p_sys->fd = -1;
    p_sys->cur_seekpoint = 0;
    p_sys->fps = var_InheritFloat( p_access, "vdr-fps" );
    ARRAY_INIT( p_sys->file_sizes );

    /* Import all files and prepare playback. */
    if( !ScanDirectory( p_access ) ||
        !SwitchFile( p_access, 0 ) )
    {
        Close( p_this );
        return VLC_EGENERIC;
    }

    ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek );
    return VLC_SUCCESS;
}
Exemplo n.º 2
0
gcc_pure
static const TCHAR *
BackslashBaseName(const TCHAR *p)
{
  if (DIR_SEPARATOR != '\\') {
    const auto *backslash = StringFindLast(p, _T('\\'));
    if (backslash != NULL)
      p = backslash + 1;
  }

  return BaseName(p);
}
Exemplo n.º 3
0
		Base* Base::GetBaseFactory()
		{
			for ( ControlFactory::List::iterator it = ControlFactory::GetList().begin(); it != ControlFactory::GetList().end(); ++it )
			{
				if ( ( *it )->Name() == BaseName() )
				{
					return *it;
				}
			}

			return NULL;
		}
Exemplo n.º 4
0
void MakeOptDest(const std::string &src, std::string &dest)
{
    TSTLStrSize len = dest.length();
    
    // Strip trailing /'s
    while (len && (dest[len-1] == '/'))
    {
        dest.erase(len-1, 1);
        len--;
    }
    
    if (IsDir(dest))
        dest = JoinPath(dest, BaseName(src));
}
Exemplo n.º 5
0
UExample::UExample()
{
	FString BaseName(TEXT("Example"));
	FRandomStream Rand;

	for (int i = 0; i < 10; i++)
	{
		FString StructName = BaseName + FString::FromInt(i);
		ExampleMap.Add(*StructName);
		ExampleMap[*StructName].Var1 = Rand.FRand();
		ExampleMap[*StructName].Var2 = Rand.FRand();
		ExampleMap[*StructName].Var3 = Rand.FRand();
		ExampleMap[*StructName].Var4 = Rand.FRand();
	}
}
Exemplo n.º 6
0
static DDS_StdString
main_file_identifier()
{
   DDS_StdString mainFile = BaseName(idl_global->main_filename()->get_string());
   char *dot = (char*)strrchr((const char*)mainFile, '.');

   if (dot)
   {
      *dot = 0;
   }

   sanitize(mainFile);

   return mainFile;
}
Exemplo n.º 7
0
static char *
defaultSystemInitFile(char *a0)
{ char plp[MAXPATHLEN];
  char *base = BaseName(PrologPath(a0, plp));
  char buf[256];
  char *s = buf;

  while(*base && isAlpha(*base))
    *s++ = *base++;
  *s = EOS;

  if ( strlen(buf) > 0 )
    return store_string(buf);

  return store_string("pl");
}
Exemplo n.º 8
0
const TCHAR *
ProfileMap::GetPathBase(const char *key) const
{
  TCHAR buffer[MAX_PATH];
  if (!Get(key, buffer, ARRAY_SIZE(buffer)))
      return nullptr;

  const TCHAR *p = buffer;
  if (DIR_SEPARATOR != '\\') {
    const auto *backslash = StringFindLast(p, _T('\\'));
    if (backslash != NULL)
      p = backslash + 1;
  }

  return BaseName(p);
}
Exemplo n.º 9
0
const TCHAR *
Profile::GetPathBase(const char *key)
{
  TCHAR buffer[MAX_PATH];
  if (!Get(key, buffer, ARRAY_SIZE(buffer)))
      return nullptr;

  const TCHAR *p = buffer;
  if (DIR_SEPARATOR != '\\') {
    const TCHAR *backslash = _tcsrchr(p, _T('\\'));
    if (backslash != NULL)
      p = backslash + 1;
  }

  return BaseName(p);
}
Exemplo n.º 10
0
static char *
defaultSystemInitFile(const char *a0)
{ char plp[MAXPATHLEN];
  char *base = BaseName(PrologPath(a0, plp, sizeof(plp)));
  char buf[256];
  char *s = buf;

  while( *base && (isAlpha(*base) || *base == '-') )
    *s++ = *base++;
  *s = EOS;

  if ( buf[0] != EOS )
    return store_string(buf);

  return store_string("swipl");
}
Exemplo n.º 11
0
/**
 * Gets a path from the profile and return its base name only.
 */
gcc_pure
static const TCHAR *
GetProfilePathBase(const TCHAR *key)
{
  const TCHAR *p = Profile::Get(key);
  if (p == NULL)
    return NULL;

  if (DIR_SEPARATOR != '\\') {
    const TCHAR *backslash = _tcsrchr(p, '\\');
    if (backslash != NULL)
      p = backslash + 1;
  }

  return BaseName(p);
}
Exemplo n.º 12
0
const TCHAR *
FileDataField::GetAsDisplayString() const
{
  if (!loaded) {
    /* get basename from postponed_value */
    const TCHAR *p = BaseName(postponed_value);
    if (p == nullptr)
      p = postponed_value;

    return p;
  }

  if (current_index < files.size())
    return files[current_index].filename;
  else
    return _T("");
}
Exemplo n.º 13
0
void
DataFieldFileReader::addFile(const TCHAR *Text, const TCHAR *PText)
{
  assert(loaded);

  // TODO enhancement: remove duplicates?

  // if too many files -> cancel
  if (files.full())
    return;

  Item &item = files.append();
  item.mTextPathFile = _tcsdup(PText);
  item.mTextFile = BaseName(item.mTextPathFile);
  if (item.mTextFile == NULL)
    item.mTextFile = item.mTextPathFile;
}
Exemplo n.º 14
0
void
DataFieldFileReader::AddFile(const TCHAR *filename, const TCHAR *path)
{
  assert(loaded);

  // TODO enhancement: remove duplicates?

  // if too many files -> cancel
  if (files.full())
    return;

  Item &item = files.append();
  item.path = _tcsdup(path);
  item.filename = BaseName(item.path);
  if (item.filename == NULL)
    item.filename = item.path;
}
Exemplo n.º 15
0
const TCHAR *
DataFieldFileReader::GetAsDisplayString() const
{
  if (!loaded) {
    /* get basename from postponed_value */
    const TCHAR *p = BaseName(postponed_value);
    if (p == NULL)
      p = postponed_value;

    return p;
  }

  if (mValue < files.size())
    return files[mValue].filename;
  else
    return _T("");
}
Exemplo n.º 16
0
void
ManagedFileListWidget::OnDownloadAdded(const TCHAR *path_relative,
                                       int64_t size, int64_t position)
{
  const TCHAR *name = BaseName(path_relative);
  if (name == NULL)
    return;

  WideToACPConverter name2(name);
  if (!name2.IsValid())
    return;

  const std::string name3(name2);

  mutex.Lock();
  downloads[name3] = DownloadStatus{size, position};
  failures.erase(name3);
  mutex.Unlock();

  SendNotification();
}
Exemplo n.º 17
0
CString CFunc::InvBase()  const
{
   CString baseName = BaseName();

   int iFwd = baseName.Find(_T("Fwd"));
   int iInv = baseName.Find(_T("Inv"));
   if (iFwd >= 0) 
      baseName = baseName.Left(iFwd) + _T("Inv") + baseName.Mid(iFwd + 3);
   if (iInv >= 0) 
      baseName = baseName.Left(iInv) + _T("Fwd") + baseName.Mid(iInv + 3);
   int iEmph = baseName.Find(_T("_"));
   CString startName;
   if (iEmph > 0) {
      startName = baseName.Left(iEmph + 1);
      baseName = baseName.Mid(iEmph + 1);
   }
   int iTo = baseName.Find(_T("To"));
   if (iTo < 0) return startName + baseName;
   baseName = baseName.Mid(iTo + 2) + _T("To") + baseName.Left(iTo);
   return startName + baseName;
}
Exemplo n.º 18
0
int twrp_restore_wrapper(const char* backup_file_image, const char* backup_path, int callback) {
    char path[PATH_MAX];
    char cmd[PATH_MAX];
    char tar_args[10];
    int ret;

    // tar vs tar.gz format?
    if ((ret = is_gzip_file(backup_file_image)) < 0)
        return ret;
    if (ret == 0)
        sprintf(tar_args, "-xvpf");
    else
        sprintf(tar_args, "-xzvpf");

    check_restore_size(backup_file_image, backup_path);
    if (strlen(backup_file_image) > strlen("win000") && strcmp(backup_file_image + strlen(backup_file_image) - strlen("win000"), "win000") == 0) {
        // multiple volume archive detected
        char main_filename[PATH_MAX];
        memset(main_filename, 0, sizeof(main_filename));
        strncpy(main_filename, backup_file_image, strlen(backup_file_image) - strlen("000"));

        int index = 0;
        sprintf(path, "%s%03i", main_filename, index);
        while (file_found(path)) {
            ui_print("  * Restoring archive %d\n", index + 1);
            sprintf(cmd, "cd /; tar %s '%s'; exit $?", tar_args, path);
            if (0 != (ret = twrp_tar_extract_wrapper(cmd, backup_path, callback)))
                return ret;
            index++;
            sprintf(path, "%s%03i", main_filename, index);
        }
    } else {
        //single volume archive
        sprintf(cmd, "cd %s; tar %s '%s'; exit $?", backup_path, tar_args, backup_file_image);
        ui_print("Restoring archive %s\n", BaseName(backup_file_image));
        ret = twrp_tar_extract_wrapper(cmd, backup_path, callback);
    }
    return ret;
}
Exemplo n.º 19
0
  void Visit(const TCHAR *path, const TCHAR *filename) {
    // Create a TaskFile instance to determine how many
    // tasks are inside of this task file
    TaskFile* task_file = TaskFile::Create(path);
    if (task_file == NULL)
      return;

    // Get base name of the task file
    const TCHAR* base_name = BaseName(path);

    // Count the tasks in the task file
    unsigned count = task_file->Count();
    // For each task in the task file
    for (unsigned i = 0; i < count; i++) {
      // Copy base name of the file into task name
      StaticString<256> name;
      name = (base_name != NULL) ? base_name : path;

      // If the task file holds more than one task
      if (count > 1) {
        if (i < task_file->namesuffixes.size() &&
            task_file->namesuffixes[i]) {

          name += _T(": ");
          name += task_file->namesuffixes[i];

        } else {
          // .. append " - Task #[n]" suffix to the task name
          name.AppendFormat(_T(": %s #%2d"), _("Task"), i + 1);
        }
      }

      // Add the task to the TaskStore
      store.push_back(TaskStore::Item(path, name.empty() ? path : name, i));
    }

    // Remove temporary TaskFile instance
    delete task_file;
  }
Exemplo n.º 20
0
// check size of archive files to get total backed up data size
// find all backup image files of a given partition and increment Backup_Size
// Backup_Size is set to 0 at start of nandroid_restore() process so that we do not print size progress on
void check_restore_size(const char* backup_file_image, const char* backup_path) {
    // refresh target partition size
    if (Get_Size_Via_statfs(backup_path) != 0) {
        Backup_Size = 0;
        return;
    }
    Before_Used_Size = Used_Size;

    char tmp[PATH_MAX];
    char filename[PATH_MAX];
    char** files;
    int numFiles = 0;

    sprintf(tmp, "%s/", DirName(backup_file_image));
    files = gather_files(tmp, "", &numFiles);

    // if it's a twrp multi volume backup, ensure we remove trailing 000: strlen("000") = 3
    if (strlen(backup_file_image) > strlen("win000") && strcmp(backup_file_image + strlen(backup_file_image) - strlen("win000"), "win000") == 0)
        snprintf(tmp, strlen(backup_file_image) - 3, "%s", backup_file_image);
    else
        strcpy(tmp, backup_file_image);
    sprintf(filename, "%s", BaseName(tmp));
    
    int i;
    unsigned long fsize;
    for(i = 0; i < numFiles; i++) {
        if (strstr(files[i], filename) != NULL) {
            fsize = Get_File_Size(files[i]);
            // check if it is a compressed archive and increase size by 45%
            // this needs a better implementation to do later
            if (is_gzip_file(files[i]) > 0)
                fsize += (fsize * 45) / 100;
            Backup_Size += fsize;
        }
    }

    free_string_array(files);
}
Exemplo n.º 21
0
int check_twrp_md5sum(const char* backup_path) {
    char md5file[PATH_MAX];
    char** files;
    int numFiles = 0;

    ui_print("\n>> Checking MD5 sums...\n");
    ensure_path_mounted(backup_path);
    files = gather_files(backup_path, "", &numFiles);
    if (numFiles == 0) {
        LOGE("No files found in %s\n", backup_path);
        free_string_array(files);
        return -1;
    }

    int i = 0;
    for(i = 0; i < numFiles; i++) {
        // exclude md5 files
        char *str = strstr(files[i], ".md5");
        if (str != NULL && strcmp(str, ".md5") == 0)
            continue;

        ui_quick_reset_and_show_progress(1, 0);
        ui_print("   - %s\n", BaseName(files[i]));
        sprintf(md5file, "%s.md5", files[i]);
        if (verify_md5digest(files[i], md5file) != 0) {
            LOGE("md5sum error!\n");
            ui_reset_progress();
            free_string_array(files);
            return -1;
        }
    }

    ui_print("MD5 sum ok.\n");
    ui_reset_progress();
    free_string_array(files);
    return 0;
}
Exemplo n.º 22
0
ppType CFunc::BaseType() const
{
   CMyString base = BaseName();
   if (base.Found(_T("64fc"))) return pp64fc;
   if (base.Found(_T("64sc"))) return pp64sc;
   if (base.Found(_T("64s" ))) return pp64s;
   if (base.Found(_T("64f" ))) return pp64f;
   if (base.Found(_T("32fc"))) return pp32fc;
   if (base.Found(_T("32sc"))) return pp32sc;
   if (base.Found(_T("32u" ))) return pp32u;
   if (base.Found(_T("32s" ))) return pp32s;
   if (base.Found(_T("32f" ))) return pp32f;
   if (base.Found(_T("24u" ))) return pp24u;
   if (base.Found(_T("24s" ))) return pp24s;
   if (base.Found(_T("16sc"))) return pp16sc;
   if (base.Found(_T("16f" ))) return pp16f;
   if (base.Found(_T("16u" ))) return pp16u;
   if (base.Found(_T("16s" ))) return pp16s;
   if (base.Found(_T("8sc" ))) return pp8sc;
   if (base.Found(_T("8u"  ))) return pp8u;
   if (base.Found(_T("8s"  ))) return pp8s;
   if (base.Found(_T("1u"  ))) return pp8u;
   return ppNONE;
}
Exemplo n.º 23
0
void
InterfaceConfigPanel::Prepare(ContainerWindow &parent, const PixelRect &rc)
{
  const UISettings &settings = CommonInterface::GetUISettings();

  RowFormWidget::Prepare(parent, rc);

  buttonFonts = ConfigPanel::GetExtraButton(1);
  assert(buttonFonts);

#ifdef HAVE_BLANK
  AddBoolean(_("Auto. blank"),
             _("This determines whether to blank the display after a long period of inactivity "
                 "when operating on internal battery power."),
             settings.display.enable_auto_blank);
#endif

  AddFileReader(_("Events"),
                _("The Input Events file defines the menu system and how XCSoar responds to "
                    "button presses and events from external devices."),
                szProfileInputFile, _T("*.xci\0"));
  SetExpertRow(InputFile);

#ifndef HAVE_NATIVE_GETTEXT
  WndProperty *wp;
  wp = AddEnum(_("Language"),
               _("The language options selects translations for English texts to other "
                   "languages. Select English for a native interface or Automatic to localise "
                   "XCSoar according to the system settings."));
  if (wp != NULL) {
    DataFieldEnum &df = *(DataFieldEnum *)wp->GetDataField();
    df.addEnumText(_("Automatic"));
    df.addEnumText(_("English"));

#ifdef HAVE_BUILTIN_LANGUAGES
    for (const struct builtin_language *l = language_table;
         l->resource != NULL; ++l)
      df.addEnumText(l->resource);
#endif

    LanguageFileVisitor lfv(df);
    VisitDataFiles(_T("*.mo"), lfv);

    df.Sort(2);

    TCHAR value[MAX_PATH];
    if (!Profile::GetPath(szProfileLanguageFile, value))
      value[0] = _T('\0');

    if (_tcscmp(value, _T("none")) == 0)
      df.Set(1);
    else if (!StringIsEmpty(value) && _tcscmp(value, _T("auto")) != 0) {
      const TCHAR *base = BaseName(value);
      if (base != NULL)
        df.SetAsString(base);
    }
    wp->RefreshDisplay();
  }
#endif /* !HAVE_NATIVE_GETTEXT */

  AddFileReader(_("Status message"),
                _("The status file can be used to define sounds to be played when certain "
                    "events occur, and how long various status messages will appear on screen."),
                szProfileStatusFile, _T("*.xcs\0"));
  SetExpertRow(StatusFile);

  AddTime(_("Menu timeout"),
          _("This determines how long menus will appear on screen if the user does not make any button "
            "presses or interacts with the computer."),
          1, 60, 1, settings.menu_timeout / 2);
  SetExpertRow(MenuTimeout);

  static gcc_constexpr_data StaticEnumChoice text_input_list[] = {
    { (unsigned)DialogSettings::TextInputStyle::Default, N_("Default") },
    { (unsigned)DialogSettings::TextInputStyle::Keyboard, N_("Keyboard") },
    { (unsigned)DialogSettings::TextInputStyle::HighScore,
      N_("HighScore Style") },
    { 0 }
  };

  AddEnum(_("Text input style"),
          _("Determines how the user is prompted for text input (filename, teamcode etc.)"),
          text_input_list, (unsigned)settings.dialog.text_input_style);
  SetExpertRow(TextInput);

  /* on-screen keyboard doesn't work without a pointing device
     (mouse or touch screen), hide the option on Altair */
  SetRowVisible(TextInput, HasPointer());

#ifdef HAVE_VIBRATOR
  static gcc_constexpr_data StaticEnumChoice haptic_feedback_list[] = {
    { (unsigned) UISettings::HapticFeedback::Default, N_("OS settings") },
    { (unsigned) UISettings::HapticFeedback::Off, N_("Off") },
    { (unsigned) UISettings::HapticFeedback::On, N_("On") },
    { 0 }
  };

  wp = AddEnum(_("Haptic feedback"),
               _("Determines if haptic feedback like vibration is used."),
               haptic_feedback_list, (unsigned)settings.haptic_feedback);
  SetExpertRow(HapticFeedback);
#endif /* HAVE_VIBRATOR */
}
Exemplo n.º 24
0
// custom raw restore handler
// used to restore efs in raw mode or modem.bin files
// for now, only called directly from outside functions (not from nandroid_restore())
// user selects an image file to restore, so backup_file_image path is already mounted
int dd_raw_restore_handler(const char* backup_file_image, const char* root) {
    ui_print("\n>> Restoring %s...\n", root);
    Volume *vol = volume_for_path(root);
    if (vol == NULL || vol->fs_type == NULL) {
        ui_print("volume not found! Skipping raw restore of %s...\n", root);
        return 0;
    }

    ui_set_background(BACKGROUND_ICON_INSTALLING);
    ui_show_indeterminate_progress();

    // make sure we  have a valid image file name
    int i = 0;
    char errmsg[PATH_MAX];
    char tmp[PATH_MAX];
    char filename[PATH_MAX];
    const char *raw_image_format[] = { ".img", ".bin", NULL };

    sprintf(filename, "%s", BaseName(backup_file_image));
    while (raw_image_format[i] != NULL) {
        if (strlen(filename) > strlen(raw_image_format[i]) &&
                    strcmp(filename + strlen(filename) - strlen(raw_image_format[i]), raw_image_format[i]) == 0 &&
                    strncmp(filename, vol->mount_point + 1, strlen(vol->mount_point)-1) == 0) {
            break;
        }
        i++;
    }

    if (raw_image_format[i] == NULL) {
        sprintf(errmsg, "invalid image file! Failed to restore %s to %s\n", filename, root);
        return print_and_error(errmsg, NANDROID_ERROR_GENERAL);
    }

    //make sure file exists
    if (!file_found(backup_file_image)) {
        sprintf(errmsg, "%s not found. Skipping restore of %s\n", backup_file_image, root);
        return print_and_error(errmsg, NANDROID_ERROR_GENERAL);
    }

    //restore raw image
    int ret = 0;
    char* device_mmcblk;

    ui_print("Restoring %s to %s\n", filename, vol->mount_point);
    if (strstr(vol->blk_device, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device, "/dev/block/mtdblock") != NULL) {
        sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, vol->blk_device, vol->mount_point);
    } else if (vol->blk_device2 != NULL &&
            (strstr(vol->blk_device2, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device2, "/dev/block/mtdblock") != NULL)) {
        sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, vol->blk_device2, vol->mount_point);
    } else if ((device_mmcblk = readlink_device_blk(root)) != NULL) {
        sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, device_mmcblk, vol->mount_point);
        free(device_mmcblk);
    } else {
        sprintf(errmsg, "raw restore: no device found (%s)\n", root);
        return print_and_error(errmsg, NANDROID_ERROR_GENERAL);
    }

    ret = __system(tmp);
    if (0 != ret) {
        sprintf(errmsg, "failed raw restore of %s to %s\n", filename, root);
        print_and_error(errmsg, ret);
    } else {
        finish_nandroid_job();
    }

    sprintf(tmp, "%s/log.txt", DirName(backup_file_image));
    ui_print_custom_logtail(tmp, 3);
    return ret;
}
Exemplo n.º 25
0
int twrp_backup_wrapper(const char* backup_path, const char* backup_file_image, int callback) {
    Volume *v = volume_for_path(backup_path);
    if (v == NULL) {
        ui_print("Unable to find volume.\n");
        return -1;
    }

    if (!is_path_mounted(backup_path)) {
        LOGE("Unable to find mounted volume: '%s'\n", v->mount_point);
        return -1;
    }

    // Always use split format (simpler code) - Build lists of files to backup
    char tmp[PATH_MAX];
    int backup_count;
    ui_print("Breaking backup file into multiple archives...\nGenerating file lists\n");
    backup_count = Make_File_List(backup_path);
    if (backup_count < 1) {
        LOGE("Error generating file list!\n");
        return -1;
    }

    // check we are not backing up an empty volume as it would fail to restore (tar: short read)
    // check first if a filelist was generated. If not, ensure volume is 0 size. Else, it could be an error while 
    if (!file_found("/tmp/list/filelist000")) {
        ui_print("Nothing to backup. Skipping %s\n", BaseName(backup_path));
        return 0;
    }

    unsigned long long total_bsize = 0, file_size = 0;
    int index;
    int nand_starts = 1;
    last_size_update = 0;
    set_perf_mode(1);
    for (index = 0; index < backup_count; index++)
    {
        compute_twrp_backup_stats(index);
        // folder /data/media and google cached music are excluded from tar by Generate_File_Lists(...)
        if (nandroid_get_default_backup_format() == NANDROID_BACKUP_FORMAT_TAR)
            sprintf(tmp, "(tar -cpvf '%s%03i' -T /tmp/list/filelist%03i) 2> /proc/self/fd/1 ; exit $?", backup_file_image, index, index);
        else
            sprintf(tmp, "set -o pipefail ; (tar -cpv -T /tmp/list/filelist%03i | pigz -c -%d >'%s%03i') 2> /proc/self/fd/1 ; exit $?", index, compression_value.value, backup_file_image, index);

        ui_print("  * Backing up archive %i/%i\n", (index + 1), backup_count);
        FILE *fp = __popen(tmp, "r");
        if (fp == NULL) {
            LOGE("Unable to execute tar.\n");
            set_perf_mode(0);
            return -1;
        }

        while (fgets(tmp, PATH_MAX, fp) != NULL) {
#ifdef PHILZ_TOUCH_RECOVERY
            if (user_cancel_nandroid(&fp, backup_file_image, 1, &nand_starts)) {
                set_perf_mode(0);
                return -1;
            }
#endif
            tmp[PATH_MAX - 1] = '\0';
            if (callback) {
                update_size_progress(backup_file_image);
                nandroid_callback(tmp);
            }
        }

#ifdef PHILZ_TOUCH_RECOVERY
        ui_print_preset_colors(0, NULL);
#endif
        if (0 != __pclose(fp)) {
            set_perf_mode(0);
            return -1;
        }

        sprintf(tmp, "%s%03i", backup_file_image, index);
        file_size = Get_File_Size(tmp);
        if (file_size == 0) {
            LOGE("Backup file size for '%s' is 0 bytes!\n", tmp);
            set_perf_mode(0);
            return -1;
        }
        total_bsize += file_size;
    }

    __system("cd /tmp && rm -rf list");
    set_perf_mode(0);
    ui_print("Total backup size:\n  %llu bytes.\n", total_bsize);
    return 0;
}
Exemplo n.º 26
0
int verify_nandroid_md5sum(const char* backup_path) {
    char* backupfile;
    char line[PATH_MAX];
    char md5file[PATH_MAX];

    ui_print("\n>> Checking MD5 sums...\n");
    ensure_path_mounted(backup_path);
    sprintf(md5file, "%s/nandroid.md5", backup_path);
    FILE *fp = fopen(md5file, "r");
    if (fp == NULL) {
        LOGE("cannot open md5file\n");
        return -1;
    }

    // unlike original cwm, an empty md5 file will fail check
    // also, if a file doesn't have and md5sum entry, it will fail
    while (fgets(line, sizeof(line), fp) != NULL) {
        backupfile = strstr(line, "  ");
        // skip empty new lines, but non other bad formatted lines
        if (backupfile == NULL && strcmp(line, "\n") != 0) {
            fclose(fp);
            return -1;
        }

        // mis-formatted line (backupfile must be at least one char as it includes the two spaces)
        if (strlen(backupfile) < 3 || strcmp(backupfile, "  \n") == 0) {
            fclose(fp);
            return -1;
        }

        // save the line before we modify it
        char *md5sum = strdup(line);
        if (md5sum == NULL) {
            LOGE("memory error\n");
            fclose(fp);
            return -1;
        }

        // remove leading two spaces and end new line
        backupfile += 2; // 2 == strlen("  ")
        if (strcmp(backupfile + strlen(backupfile) - 1, "\n") == 0)
            backupfile[strlen(backupfile) - 1] = '\0';

        // create a temporary md5file for each backup file
        sprintf(md5file, "/tmp/%s.md5", backupfile);
        write_string_to_file(md5file, md5sum);
        free(md5sum);
    }

    fclose(fp);

    // verify backup integrity for each backupfile to the md5sum we saved in temporary md5file
    int i = 0;
    int numFiles = 0;
    char** files;
    set_gather_hidden_files(1);
    files = gather_files(backup_path, "", &numFiles);
    set_gather_hidden_files(1);
    if (numFiles == 0) {
        free_string_array(files);
        return -1;
    }

    for(i = 0; i < numFiles; i++) {
        // exclude md5 and log files
        if (strcmp(BaseName(files[i]), "nandroid.md5") == 0 || strcmp(BaseName(files[i]), "recovery.log") == 0)
            continue;

        ui_quick_reset_and_show_progress(1, 0);
        sprintf(md5file, "/tmp/%s.md5", BaseName(files[i]));
        ui_print("  > %s\n", BaseName(files[i]));
        if (verify_md5digest(files[i], md5file) != 0) {
            free_string_array(files);
            ui_reset_progress();
            return -1;
        }
        delete_a_file(md5file);
    }

    ui_reset_progress();
    free_string_array(files);
    return 0;
}
Exemplo n.º 27
0
string CFileCode::GetBaseFileBaseName(void) const
{
    _ASSERT(BaseName(GetFileBaseName()).size() + 5 <= MAX_FILE_NAME_LENGTH);
    return GetFileBaseName() + "_";
}
Exemplo n.º 28
0
bool
InterfaceConfigPanel::Save(bool &_changed)
{
  UISettings &settings = CommonInterface::SetUISettings();
  bool changed = false;;

#ifdef HAVE_BLANK
  changed |= SaveValue(AutoBlank, ProfileKeys::AutoBlank,
                       settings.display.enable_auto_blank);
#endif

  if (SaveValueFileReader(InputFile, ProfileKeys::InputFile))
    require_restart = changed = true;

#ifndef HAVE_NATIVE_GETTEXT
  WndProperty *wp = (WndProperty *)&GetControl(LanguageFile);
  if (wp != NULL) {
    DataFieldEnum &df = *(DataFieldEnum *)wp->GetDataField();

    TCHAR old_value[MAX_PATH];
    if (!Profile::GetPath(ProfileKeys::LanguageFile, old_value))
      old_value[0] = _T('\0');

    const TCHAR *old_base = BaseName(old_value);
    if (old_base == NULL)
      old_base = old_value;

    TCHAR buffer[MAX_PATH];
    const TCHAR *new_value, *new_base;

    switch (df.GetValue()) {
    case 0:
      new_value = new_base = _T("auto");
      break;

    case 1:
      new_value = new_base = _T("none");
      break;

    default:
      _tcscpy(buffer, df.GetAsString());
      ContractLocalPath(buffer);
      new_value = buffer;
      new_base = BaseName(new_value);
      if (new_base == NULL)
        new_base = new_value;
      break;
    }

    if (_tcscmp(old_value, new_value) != 0 &&
        _tcscmp(old_base, new_base) != 0) {
      Profile::Set(ProfileKeys::LanguageFile, new_value);
      LanguageChanged = changed = true;
    }
  }
#endif

  if (SaveValueFileReader(StatusFile, ProfileKeys::StatusFile))
    require_restart = changed = true;

  unsigned menu_timeout = GetValueInteger(MenuTimeout) * 2;
  if (settings.menu_timeout != menu_timeout) {
    settings.menu_timeout = menu_timeout;
    Profile::Set(ProfileKeys::MenuTimeout, menu_timeout);
    changed = true;
  }

#ifdef HAVE_VIBRATOR
  changed |= SaveValueEnum(HapticFeedback, ProfileKeys::HapticFeedback, settings.haptic_feedback);
#endif

  _changed |= changed;
  return true;
}
Exemplo n.º 29
0
void
InterfaceConfigPanel::Prepare(ContainerWindow &parent, const PixelRect &rc)
{
  const UISettings &settings = CommonInterface::GetUISettings();

  RowFormWidget::Prepare(parent, rc);

  buttonFonts = ConfigPanel::GetExtraButton(1);
  assert(buttonFonts);

#ifdef HAVE_BLANK
  AddBoolean(_("Auto. blank"),
             _("This determines whether to blank the display after a long period of inactivity "
                 "when operating on internal battery power."),
             settings.display.enable_auto_blank);
#endif

  AddFileReader(_("Events"),
                _("The Input Events file defines the menu system and how XCSoar responds to "
                    "button presses and events from external devices."),
                ProfileKeys::InputFile, _T("*.xci\0"));
  SetExpertRow(InputFile);

#ifndef HAVE_NATIVE_GETTEXT
  WndProperty *wp;
  wp = AddEnum(_("Language"),
               _("The language options selects translations for English texts to other "
                   "languages. Select English for a native interface or Automatic to localise "
                   "XCSoar according to the system settings."));
  if (wp != NULL) {
    DataFieldEnum &df = *(DataFieldEnum *)wp->GetDataField();
    df.addEnumText(_("Automatic"));
    df.addEnumText(_T("English"));

#ifdef HAVE_BUILTIN_LANGUAGES
    for (const BuiltinLanguage *l = language_table;
         l->resource != NULL; ++l) {
      StaticString<100> display_string;
      display_string.Format(_T("%s (%s)"), l->name, l->resource);
      df.addEnumText(l->resource, display_string);
    }
#endif

    LanguageFileVisitor lfv(df);
    VisitDataFiles(_T("*.mo"), lfv);

    df.Sort(2);

    TCHAR value[MAX_PATH];
    if (!Profile::GetPath(ProfileKeys::LanguageFile, value))
      value[0] = _T('\0');

    if (StringIsEqual(value, _T("none")))
      df.Set(1);
    else if (!StringIsEmpty(value) && !StringIsEqual(value, _T("auto"))) {
      const TCHAR *base = BaseName(value);
      if (base != NULL)
        df.Set(base);
    }
    wp->RefreshDisplay();
  }
#endif /* !HAVE_NATIVE_GETTEXT */

  AddFileReader(_("Status message"),
                _("The status file can be used to define sounds to be played when certain "
                    "events occur, and how long various status messages will appear on screen."),
                ProfileKeys::StatusFile, _T("*.xcs\0"));
  SetExpertRow(StatusFile);

  AddTime(_("Menu timeout"),
          _("This determines how long menus will appear on screen if the user does not make any button "
            "presses or interacts with the computer."),
          1, 60, 1, settings.menu_timeout / 2);
  SetExpertRow(MenuTimeout);

  #ifdef HAVE_VIBRATOR
  static constexpr StaticEnumChoice haptic_feedback_list[] = {
    { (unsigned)UISettings::HapticFeedback::DEFAULT, N_("OS settings") },
    { (unsigned)UISettings::HapticFeedback::OFF, N_("Off") },
    { (unsigned)UISettings::HapticFeedback::ON, N_("On") },
    { 0 }
  };

  wp = AddEnum(_("Haptic feedback"),
               _("Determines if haptic feedback like vibration is used."),
               haptic_feedback_list, (unsigned)settings.haptic_feedback);
  SetExpertRow(HapticFeedback);
#endif /* HAVE_VIBRATOR */
}
Exemplo n.º 30
0
int main(int argc, char **argv){
     int i;
     char *p;
     GC_INIT();
     ::cgc1::cgc_root_t hash_bucket_root(hash_buckets);
     hash_buckets=reinterpret_cast<node*>(::cgc1::cgc_malloc(sizeof(node)*7313));
     progname = BaseName(argv[0]);
     yyinit();
     for (p=argv[0]; *p; p++) if (*p=='/') progname = p+1;
     for (i=1; i<argc; i++) {
     	  if (EQUAL == strcmp(argv[i],"--help")) {
	       usage();
	       exit(0);
	       }
     	  if (EQUAL == strcmp(argv[i],"-dep")) {
	       stop_after_dep = TRUE;
	       continue;
	       }
     	  if (EQUAL == strcmp(argv[i],"-cxx")) {
	       do_cxx = TRUE;
	       continue;
	       }
     	  if (EQUAL == strcmp(argv[i],"-noline")) {
	       noline = TRUE;
	       continue;
	       }
	  if (EQUAL == strcmp(argv[i],"-pthreadlocal")) {
	       pthreadThreadLocal=TRUE;
               compilerThreadLocal=FALSE;
               continue;
	       }
     	  if (EQUAL == strcmp(argv[i],"-typecodes")) {
	       printtypecodes();
	       return 0;
	       }
     	  if (EQUAL == strcmp(argv[i],"-noarraychks")) {
	       arraychks = FALSE;
	       continue;
	       }
     	  if (EQUAL == strcmp(argv[i],"-nocasechks")) {
	       casechks = FALSE;
	       continue;
	       }
	  if (EQUAL == strcmp(argv[i],"-nomacros")) {
	       nomacros = TRUE;
	       continue;
	       }
     	  if (EQUAL == strcmp(argv[i],"-O")) {
	       arraychks = FALSE;
	       casechks = FALSE;
	       continue;
	       }
	  if (EQUAL == strcmp(argv[i],"-tabwidth")) {
	       i++;
	       if (i < argc) tabwidth = atoi(argv[i]);
	       continue;
	       }
	  if (EQUAL == strcmp(argv[i],"-yydebug")) {
	       yydebug = 1;
	       continue;
	       }
	  if (EQUAL == strcmp(argv[i],"-debug")) {
	       debug = TRUE;
	       continue;
	       }
	  if (EQUAL == strcmp(argv[i],"-v")) {
	       puts(Version);
     	       puts(Copyright);
	       continue;
	       }
     	  if ('-' == argv[i][0] && 'I' == argv[i][1]) {
	       if (argv[i][2] == 0) {
		    error("-I option: missing directory");
		    usage();
		    exit(1);
		    }
	       char buf[256];
	       strcpy(buf,sigpath);
	       strcat(buf,":");
	       strcat(buf,argv[i]+2);
	       sigpath = strperm(buf);
	       continue;
	       }
	  if ('-' == argv[i][0]) {
	       error("unrecognized option %s\n",argv[i]);
	       usage();
	       exit(1);
	       }
	  if ( EQUAL == strcmp(".d",tail(argv[i])) || EQUAL == strcmp(".dd",tail(argv[i])) ) {
	       node f;
	       do_this_cxx = do_cxx || EQUAL == strcmp(".dd",tail(argv[i]));
	       global_scope = new(struct SCOPE);
	       readsetup(global_scope);
	       targetname = newsuffixbase(argv[i],"");
	       f = readfile(argv[i]);
	       if (debug) {
		    char *n = newsuffixbase(argv[i],".out");
		    if (NULL == freopen(n,"w", stdout)) {
			 fatal("can't open file %s",n);
			 }
		    put("After parsing:\n");
		    pp(f);
		    fflush(stdout);
		    }
	       outfilename = newsuffixbase(argv[i], do_this_cxx ? "-tmp.cc" : "-tmp.c");
	       {
		    char *n = newsuffixbase(argv[i],".dep.tmp");
		    dependfile = fopen(n,"w");
		    if (dependfile == NULL) fatal("can't open file %s",n);
		    }
	       f = chkprogram(f);
	       if (debug) {
		    char *n = newsuffixbase(argv[i],".log");
		    if (NULL == freopen(n,"w", stdout)) {
			 fatal("can't open file %s",n);
			 }
		    pprintl(f);
		    }
	       {
		    node t = global_scope->signature;
		    char *n = newsuffixbase(argv[i],".sig.tmp");
		    if (NULL == freopen(n,"w", stdout)) {
			 fatal("can't open file %s",n);
			 }
		    printf("-- generated by %s\n\n",progname);
		    while (t != NULL) {
			 dprint(CAR(t));
			 put(";\n");
			 t = CDR(t);
			 }
		    }
	       if (stop_after_dep) quit();
	       checkfordeferredsymbols();
	       if (debug) {
		    char *n = newsuffixbase(argv[i],".sym");
		    if (NULL == freopen(n,"w", stdout)) {
			 fatal("can't open file %s",n);
			 }
		    printsymboltable();
		    printtypelist();
		    printstringlist();
		    }
	       if (n_errors > 0) {
		    quit();
		    }
	       if (TRUE) {
		    char *n = newsuffixbase(argv[i],"-exports.h.tmp");
		    if (NULL == freopen(n,"w", stdout)) {
			 fatal("can't open file %s",n);
			 }
		    printf("#ifndef %s_included\n",targetname);
		    printf("#define %s_included\n",targetname);
		    declarationsstrings = reverse(declarationsstrings);
		    while (declarationsstrings) {
			 node s = unpos(car(declarationsstrings));
			 assert(isstrconst(s));
			 put_unescape(s->body.string_const.characters);
			 put("\n");
			 declarationsstrings = cdr(declarationsstrings);
			 }
		    put(declarations_header);
		    /* printtypecodes(); */
		    cprinttypes();
		    put(declarations_trailer);
		    put("#endif\n");
		    }
	       if (TRUE) {
		    if (NULL == freopen(outfilename,"w", stdout)) {
			 fatal("can't open file %s",outfilename);
			 }
		    printf("#include \"%s\"\n",newsuffixbase(argv[i],"-exports.h"));
		    put(code_header);
		    headerstrings = reverse(headerstrings);
		    while (headerstrings) {
			 locn(car(headerstrings));
			 printpos();
			 node s = unpos(car(headerstrings));
			 assert(isstrconst(s));
			 put_unescape(s->body.string_const.characters);
			 put("\n");
			 locn(NULL);
			 headerstrings = cdr(headerstrings);
			 }
		    cprintsemi(f);
		    }
	       }
	  else {
	       fprintf(stderr,"unknown file type %s\n",argv[i]);
	       usage();
	       exit(1);
	       }
	  }
     quit();
     return 0;
     }