Esempio n. 1
0
/*
 *  Initialize the dialog box
 */
static void InitDlgBox(WINDOW wnd)
{
    if (*FileSpec)
        PutItemText(wnd, ID_FILENAME, FileSpec);
	if (BuildFileList(wnd, SrchSpec))
		BuildDirectoryList(wnd);
	BuildDriveList(wnd);
	BuildPathDisplay(wnd);
}
Esempio n. 2
0
bool AvHSoundListManager::BuildSoundList(const string& inDirName, CStringList& outList)
{
	bool theSuccess = false;

	string theBaseDirectoryName = string(getModDirectory()) + string("/") + string(kSoundDirectory) + string("/");
	string theFullDirName = inDirName;
	if(BuildFileList(theBaseDirectoryName, theFullDirName, "*.wav", outList))
	{
	    theSuccess = true;
	}
	
	return theSuccess;
}
Esempio n. 3
0
void GotoFileDlg::OnIdle(wxIdleEvent& event) {
	if (!m_project.HasProject()) return; // No project, so no files to load.
	if (m_filesLoaded) return; // Already done loading files.

	if (m_dirStack.empty()) {
		const wxString root_path = m_project.GetRoot().GetPath();
		m_files.reserve(100);
		BuildFileList(root_path);
	}
	else {
		DirState& dirState = *m_dirStack.back();

		// Get next subdir
		if (dirState.WalkFolders()) {
			const wxString fulldirname = dirState.FullFolderName();
			wxLogDebug(fulldirname);
			BuildFileList(fulldirname);
		}
		else {
			// All sub-dirs visited
			if (dirState.info) {
				m_filters.pop_back();
				delete dirState.info;
			}

			delete m_dirStack.back();
			m_dirStack.pop_back();

			if (m_dirStack.empty())
				m_filesLoaded = true;
		}
	}

	m_cmdList->UpdateList();
	if (!m_dirStack.empty()) event.RequestMore();
}
Esempio n. 4
0
/*!
 * Creates a list with the files al files in the defined \a directory
 * and its subdirectories.
 */
void PluginManager::BuildFileList( QDir directory, QStringList& filesList )
{
	AddFilesToList( directory, filesList );

	QString directoryPath( directory.absolutePath().append( QLatin1String( "/" ) ) );
    QStringList subdirectoriesList = directory.entryList( QDir::Dirs, QDir::Unsorted );

   for( int i = 0; i< subdirectoriesList.size(); ++i )
   {
    	QString subdirectoryName = subdirectoriesList[i];
   		if( ValidDirectoryName( subdirectoryName ) )
   			BuildFileList( QDir( directoryPath + subdirectoryName ), filesList );
   	}

}
Esempio n. 5
0
//---------------------------------------------
//  nsZipArchive::OpenArchive
//---------------------------------------------
nsresult nsZipArchive::OpenArchive(PRFileDesc * fd)
{
  if (!fd)
    return ZIP_ERR_PARAM;

#ifndef STANDALONE
  // Initialize our arena
  PL_INIT_ARENA_POOL(&mArena, "ZipArena", ZIP_ARENABLOCKSIZE);
#endif

  //-- Keep the filedescriptor for further reading...
  mFd = fd;

  //-- get table of contents for archive
  return BuildFileList();
}
Esempio n. 6
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *sourcetreebase - 
//			*subdir - 
//			*baseentityclass - 
//-----------------------------------------------------------------------------
void ProcessSourceDirectory( char const *basedir )
{
	vprint( 0, "building .qc list\n" );

	CUtlVector< CUtlSymbol > files;

	BuildFileList( files, basedir, ".qc" );

	vprint( 0, "found %i .qc files\n\n", files.Count() );

	int offset = strlen( basedir ) + 1;

	// Add files to QC Files dictionary
	int c = files.Count();
	for ( int i = 0; i < c; i++ )
	{
		QCFile qcf;
		memset( &qcf, 0, sizeof( qcf ) );
		CUtlSymbol& sym = files[ i ];
		g_Analysis.files.Insert( g_Analysis.symbols.String( sym ), qcf );
	}

	// Now iterate .qc files, looking into each to find the output model name
	c = g_Analysis.files.Count();
	int valid = 0;
	for ( int i = 0; i < c; i++ )
	{
		char modelname[ 256 ];
		char const *filename = g_Analysis.files.GetElementName( i );
		if ( verbose )
		{
			vprint( 0, "checking %i: %s\n", i, filename );
		}
		if ( GetModelNameFromSourceFile( filename, modelname, sizeof( modelname ) ) )
		{
			if ( AddModelNameFromSource( g_Analysis.models, filename, modelname, offset ) )
			{
				valid++;
			}
		}
	}

	int ecount = c - valid;
	vprint( 0, "\n summary:  found %i/%i (%.2f percent) .qc errors\n\n", ecount, c, 100.0 * ecount / max( c, 1 ) );
}
Esempio n. 7
0
 virtual void OnInvalidateData(int data)
 {
     switch (data) {
     case 0:
         /* Rescan files */
         this->selected = NULL;
         _load_check_data.Clear();
         BuildFileList();
     /* FALL THROUGH */
     case 1:
         /* Selection changes */
         if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
             this->SetWidgetDisabledState(SLWW_LOAD_BUTTON,
                                          this->selected == NULL || _load_check_data.HasErrors());
             this->SetWidgetDisabledState(SLWW_NEWGRF_INFO,
                                          !_load_check_data.HasNewGrfs());
         }
         break;
     }
 }
Esempio n. 8
0
BOOL CPicapDoc::UpdateFileList(CString path)
{
	// if the folder is changed, the file list needs to be updated
	CString folder = GetFolderByPath(path);
	if (IsFolderChanged(folder))
	{
		m_currentFolder = folder;
		if (!BuildFileList(folder))
		{
			return FALSE;
		}
		// file iterator needs to be updated
		if (!UpdateFileIterator(path))
		{
			return FALSE;
		}
	}

	return TRUE;
}
Esempio n. 9
0
void ProcessModelsDirectory( char const *basedir )
{
	vprint( 0, "building .mdl list\n" );

	CUtlVector< CUtlSymbol > models;

	BuildFileList( models, basedir, ".mdl" );

	vprint( 0, "found %i .mdl files\n\n", models.Count() );

	int offset = strlen( basedir ) + 1;

	// Now iterate model files and check version tag and whether a .qc exists which builds the .mdl

	// Add files to QC Files dictionary
	int c = models.Count();
	int valid = 0;
	for ( int i = 0; i < c; i++ )
	{
		QCFile qcf;
		memset( &qcf, 0, sizeof( qcf ) );
		CUtlSymbol& sym = models[ i ];

		char const *modelname = g_Analysis.symbols.String( sym );

		if ( verbose )
		{
			vprint( 0, "checking %i .mdl %s\n", i, modelname );
		}

		if ( ValidateModelFile( modelname, offset ) )
		{
			valid++;
		}
	}

	int ecount = c - valid;
	vprint( 0, "\n summary:  found %i/%i (%.2f percent) .mdl errors\n", ecount, c, 100.0 * ecount / max( c, 1 ) );

}
Esempio n. 10
0
/*!
 * \brief Builds a list of all the files found descending recursively
 *        into the given directory
 *
 * \param directory Directory to begin search
 * \param music_files A pointer to the MusicLoadedMap to store the results
 * \param parentid The id of the parent directory in the music_directories
 *                 table. The root directory should have an id of 0
 *
 * \returns Nothing.
 */
void FileScanner::BuildFileList(QString &directory, MusicLoadedMap &music_files, int parentid)
{
    QDir d(directory);

    if (!d.exists())
        return;

    QFileInfoList list = d.entryInfoList();
    if (list.isEmpty())
        return;

    QFileInfoList::const_iterator it = list.begin();
    const QFileInfo *fi;

    /* Recursively traverse directory, calling QApplication::processEvents()
       every now and then to ensure the UI updates */
    int update_interval = 0;
    int newparentid = 0;
    while (it != list.end())
    {
        fi = &(*it);
        ++it;
        if (fi->fileName() == "." || fi->fileName() == "..")
            continue;
        QString filename = fi->absoluteFilePath();
        if (fi->isDir())
        {

            QString dir(filename);
            dir.remove(0, m_startdir.length());

            newparentid = m_directoryid[dir];

            if (newparentid == 0)
            {
                int id = GetDirectoryId(dir, parentid);
                m_directoryid[dir] = id;

                if (id > 0)
                {
                    newparentid = id;
                }
                else
                {
                    LOG(VB_GENERAL, LOG_ERR,
                        QString("Failed to get directory id for path %1")
                            .arg(dir));
                }
            }

            BuildFileList(filename, music_files, newparentid);

            qApp->processEvents ();
        }
        else
        {
            if (++update_interval > 100)
            {
                qApp->processEvents();
                update_interval = 0;
            }

            music_files[filename] = kFileSystem;
        }
    }
}
Esempio n. 11
0
/*!
 * \brief Scan a directory recursively for music and albumart.
 *        Inserts, updates and removes any files any files found in the
 *        database.
 *
 * \param directory Directory to scan
 *
 * \returns Nothing.
 */
void FileScanner::SearchDir(QString &directory)
{

    m_startdir = directory;

    MusicLoadedMap music_files;
    MusicLoadedMap::Iterator iter;

    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");

    QString message = QObject::tr("Searching for music files");

    MythUIBusyDialog *busy = new MythUIBusyDialog(message, popupStack,
                                                  "musicscanbusydialog");

    if (busy->Create())
        popupStack->AddScreen(busy, false);
    else
        busy = NULL;

    BuildFileList(m_startdir, music_files, 0);

    if (busy)
        busy->Close();

    ScanMusic(music_files);
    ScanArtwork(music_files);

    message = QObject::tr("Updating music database");
    MythUIProgressDialog *file_checking = new MythUIProgressDialog(message,
                                                    popupStack,
                                                    "scalingprogressdialog");

    if (file_checking->Create())
    {
        popupStack->AddScreen(file_checking, false);
        file_checking->SetTotal(music_files.size());
    }
    else
    {
        delete file_checking;
        file_checking = NULL;
    }

     /*
       This can be optimised quite a bit by consolidating all commands
       via a lot of refactoring.

       1) group all files of the same decoder type, and don't
       create/delete a Decoder pr. AddFileToDB. Or make Decoders be
       singletons, it should be a fairly simple change.

       2) RemoveFileFromDB should group the remove into one big SQL.

       3) UpdateFileInDB, same as 1.
     */

    uint counter = 0;
    for (iter = music_files.begin(); iter != music_files.end(); iter++)
    {
        if (*iter == kFileSystem)
            AddFileToDB(iter.key());
        else if (*iter == kDatabase)
            RemoveFileFromDB(iter.key ());
        else if (*iter == kNeedUpdate)
            UpdateFileInDB(iter.key());

        if (file_checking)
        {
            file_checking->SetProgress(++counter);
            qApp->processEvents();
        }
    }
    if (file_checking)
        file_checking->Close();

    // Cleanup orphaned entries from the database
    cleanDB();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : argc - 
//			argv[] - 
// Output : int
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
	SpewOutputFunc( SpewFunc );
	SpewActivate( "unusedcontent", 2 );

	CommandLine()->CreateCmdLine( argc, argv );

	int i=1;
	for ( i ; i<argc ; i++)
	{
		if ( argv[ i ][ 0 ] == '-' )
		{
			switch( argv[ i ][ 1 ] )
			{
			case 'l':
				uselogfile = true;
				break;
			case 'v':
				verbose = true;
				break;
			case 'r':
				showreferencedfiles = true;
				break;
			case 'd':
				spewdeletions = true;
				break;
			case 'i':
				immediatedelete = true;
				break;
			case 'w':
				printwhitelist = true;
				break;
			case 'm':
				showmapfileusage = true;
				break;
			case 'g':
				// Just skip -game
				Assert( !Q_stricmp( argv[ i ], "-game" ) );
				++i;
				break;
			case 'f':
				// grab reslists folder
				{
					++i;
					Q_strncpy( g_szReslistDir, argv[ i ], sizeof( g_szReslistDir ) );
					Q_strlower( g_szReslistDir );
					Q_FixSlashes( g_szReslistDir );
					Q_AppendSlash( g_szReslistDir, sizeof( g_szReslistDir ) );
					
				}
				break;
			default:
				printusage();
				break;
			}
		}
	}

	if ( argc < 3 || ( i != argc ) )
	{
		PrintHeader();
		printusage();
		return 0;
	}

	CheckLogFile();

	PrintHeader();

	vprint( 0, "    Using reslist dir '%s'\n", g_szReslistDir );

	vprint( 0, "    Looking for extraneous content...\n" );

	char resfile[ 256 ];
	strcpy( resfile, argv[ i - 1 ] );

	vprint( 0, "    Comparing results of resfile (%s) with files under current directory...\n",	resfile );

	char workingdir[ 256 ];
	workingdir[0] = 0;
	Q_getwd( workingdir, sizeof( workingdir ) );

	// If they didn't specify -game on the command line, use VPROJECT.
	CmdLib_InitFileSystem( workingdir );

	filesystem = (IFileSystem *)(CmdLib_GetFileSystemFactory()( FILESYSTEM_INTERFACE_VERSION, NULL ));
	if ( !filesystem )
	{
		AssertMsg( 0, "Failed to create/get IFileSystem" );
		return 1;
	}

	g_pFullFileSystem->RemoveAllSearchPaths();
	g_pFullFileSystem->AddSearchPath(gamedir, "GAME");

	Q_strlower( gamedir );
	Q_FixSlashes( gamedir );

	//
	//ProcessMaterialsDirectory( vmtdir );

	// find out the mod dir name
	Q_strncpy( modname, gamedir, sizeof(modname) );
	modname[ strlen(modname) - 1] = 0;

	if ( strrchr( modname,  '\\' ) )
	{
		Q_strncpy( modname, strrchr( modname, '\\' ) + 1, sizeof(modname) );
	}
	else
	{
		Q_strncpy( modname, "", sizeof(modname) );
	}
	vprint( 1, "Mod Name:%s\n", modname);


	BuildCheckdirList();
	BuildWhiteList();

	vprint( 0, "Building aggregate file list from resfile output\n" );
	CUtlRBTree< ReferencedFile, int > referencedfiles( 0, 0, RefFileLessFunc );
	CUtlVector< UnusedContent::CUtlSymbol >	resfiles;

	BuildReferencedFileList( resfiles, referencedfiles, resfile );

	vprint( 0, "found %i files\n\n", referencedfiles.Count() );

	vprint( 0, "Building list of all game content files\n" );
	CUtlVector< FileEntry > contentfiles;
	CUtlVector< FileEntry > otherfiles;
	BuildFileList( 0, contentfiles, &otherfiles, "", 0 );
	vprint( 0, "found %i files in content tree\n\n", contentfiles.Count() );

	Correlate( referencedfiles, contentfiles, modname );

	// now output the files not referenced in the whitelist or general reslists
	filesystem->RemoveFile( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "GAME" );
	int c = otherfiles.Count();
	for ( i = 0; i < c; ++i )
	{
		FileEntry & entry = otherfiles[ i ];
		char const *name = g_Analysis.symbols.String( entry.sym );

		logprint( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, name );
	}

	// also include the files from deletions.bat, as we don't actually run that now
	c = contentfiles.Count();
	for ( i = 0; i < c; ++i )
	{
		FileEntry & entry = contentfiles[ i ];
		if ( entry.referenced != REFERENCED_NO )
			continue;

		char const *fn = g_Analysis.symbols.String( entry.sym );
		logprint( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, fn );
	}

	FileSystem_Term();

	return 0;
}
Esempio n. 13
0
/*!
 * Loads all the valid plugins from "plugins" subdirecotry of the directory in
 * which the running version of Tonatiuh is located.
 */
void PluginManager::LoadAvailablePlugins( QDir pluginsDirectory )
{
	QStringList filesList;
	BuildFileList( pluginsDirectory, filesList );
	foreach( QString fileName, filesList ) LoadTonatiuhPlugin( fileName );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : argc -
//			argv[] -
// Output : int
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
    SpewOutputFunc( SpewFunc );
    SpewActivate( "vcd_sound_check", 2 );

    int i=1;
    for ( i ; i<argc ; i++)
    {
        if ( argv[ i ][ 0 ] == '-' )
        {
            switch( argv[ i ][ 1 ] )
            {
            case 'l':
                uselogfile = true;
                break;
            case 'v':
                verbose = true;
                break;
            case 'm':
                spewmoveto = true;
                break;
            case 'o':
                vcdonly = true;
                break;
            default:
                printusage();
                break;
            }
        }
    }

    if ( argc < 3 || ( i != argc ) )
    {
        PrintHeader();
        printusage();
    }

    CheckLogFile();

    PrintHeader();

    vprint( 0, "    Looking for .wav files not referenced in .vcd files...\n" );

    char sounddir[ 256 ];
    char vcddir[ 256 ];
    strcpy( sounddir, argv[ i - 2 ] );
    strcpy( vcddir, argv[ i - 1 ] );
    if ( !strstr( sounddir, "sound" ) )
    {
        vprint( 0, "Sound dir %s looks invalid (format:  u:/tf2/hl2/sound/vo)\n", sounddir );
        return 0;
    }
    if ( !strstr( vcddir, "scenes" ) )
    {
        vprint( 0, ".vcd dir %s looks invalid (format:  u:/tf2/hl2/scenes)\n", vcddir );
        return 0;
    }

    char workingdir[ 256 ];
    workingdir[0] = 0;
    Q_getwd( workingdir, sizeof( workingdir ) );

    // If they didn't specify -game on the command line, use VPROJECT.
    CmdLib_InitFileSystem( workingdir );

    CSysModule *pSoundEmitterModule = g_pFullFileSystem->LoadModule( "soundemittersystem.dll" );
    if ( !pSoundEmitterModule )
    {
        vprint( 0, "Sys_LoadModule( soundemittersystem.dll ) failed!\n" );
        return 0;
    }

    CreateInterfaceFn hSoundEmitterFactory = Sys_GetFactory( pSoundEmitterModule );
    if ( !hSoundEmitterFactory )
    {
        vprint( 0, "Sys_GetFactory on soundemittersystem.dll failed!\n" );
        return 0;
    }

    soundemitter = ( ISoundEmitterSystemBase * )hSoundEmitterFactory( SOUNDEMITTERSYSTEM_INTERFACE_VERSION, NULL );
    if ( !soundemitter )
    {
        vprint( 0, "Couldn't get interface %s from soundemittersystem.dll!\n", SOUNDEMITTERSYSTEM_INTERFACE_VERSION );
        return 0;
    }

    filesystem = (IFileSystem *)(CmdLib_GetFileSystemFactory()( FILESYSTEM_INTERFACE_VERSION, NULL ));
    if ( !filesystem )
    {
        AssertMsg( 0, "Failed to create/get IFileSystem" );
        return 1;
    }

    Q_FixSlashes( gamedir );
    Q_strlower( gamedir );

    vprint( 0, "game dir %s\nsounds dir %s\nvcd dir %s\n\n",
            gamedir,
            sounddir,
            vcddir );

    Q_StripTrailingSlash( sounddir );
    Q_StripTrailingSlash( vcddir );


    filesystem->RemoveFile( "moveto.txt", "GAME" );
    //
    //ProcessMaterialsDirectory( vmtdir );

    vprint( 0, "Initializing sound emitter system\n" );
    soundemitter->Connect( FileSystem_GetFactory() );
    soundemitter->Init();

    vprint( 0, "Loaded %i sounds\n", soundemitter->GetSoundCount() );

    vprint( 0, "Building list of .vcd files\n" );
    CUtlVector< CUtlSymbol > vcdfiles;
    BuildFileList( vcdfiles, vcddir, ".vcd" );
    vprint( 0, "found %i .vcd files\n\n", vcdfiles.Count() );

    vprint( 0, "Building list of known .wav files\n" );
    CUtlVector< CUtlSymbol > wavfiles;
    BuildFileList( wavfiles, sounddir, ".wav" );
    vprint( 0, "found %i .wav files\n\n", wavfiles.Count() );

    CorrelateWavsAndVCDs( vcdfiles, wavfiles );

    soundemitter->Shutdown();
    soundemitter = 0;
    g_pFullFileSystem->UnloadModule( pSoundEmitterModule );

    FileSystem_Term();

    return 0;
}
Esempio n. 15
0
int WINAPI _tWinMain (HINSTANCE hThisInstance,
                    UNUSED HINSTANCE hPrevInstance,
                    UNUSED LPTSTR lpszArgument,
                    UNUSED int nCmdShow)
{
  MSG messages;            /* Here messages to the application are saved */
  WNDCLASSEX wincl;        /* Data structure for the windowclass */
  DWORD shell32_version;

  /* Initialize handlers for manangement interface notifications */
  mgmt_rtmsg_handler handler[] = {
      { ready,    OnReady },
      { hold,     OnHold },
      { log,      OnLogLine },
      { state,    OnStateChange },
      { password, OnPassword },
      { proxy,    OnProxy },
      { stop,     OnStop },
      { 0,        NULL }
  };
  InitManagement(handler);

  /* initialize options to default state */
  InitOptions(&o);

#ifdef DEBUG
  /* Open debug file for output */
  if (!(o.debug_fp = fopen(DEBUG_FILE, "w")))
    {
      /* can't open debug file */
      ShowLocalizedMsg(IDS_ERR_OPEN_DEBUG_FILE, DEBUG_FILE);
      exit(1);
    }
  PrintDebug(_T("Starting OpenVPN GUI v%S"), PACKAGE_VERSION);
#endif


  o.hInstance = hThisInstance;

  if(!GetModuleHandle(_T("RICHED20.DLL")))
    {
      LoadLibrary(_T("RICHED20.DLL"));
    }
  else
    {
      /* can't load riched20.dll */
      ShowLocalizedMsg(IDS_ERR_LOAD_RICHED20);
      exit(1);
    }

  /* Check version of shell32.dll */
  shell32_version=GetDllVersion(_T("shell32.dll"));
  if (shell32_version < PACKVERSION(5,0))
    {
      /* shell32.dll version to low */
      ShowLocalizedMsg(IDS_ERR_SHELL_DLL_VERSION, shell32_version);
      exit(1);
    }
#ifdef DEBUG
  PrintDebug(_T("Shell32.dll version: 0x%lx"), shell32_version);
#endif


  /* Parse command-line options */
  ProcessCommandLine(&o, GetCommandLine());

  /* Check if a previous instance is already running. */
  if ((FindWindow (szClassName, NULL)) != NULL)
    {
        /* GUI already running */
        ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING);
        exit(1);
    }

  if (!GetRegistryKeys()) {
    exit(1);
  }
  if (!CheckVersion()) {
    exit(1);
  }

  if (!EnsureDirExists(o.log_dir))
  {
    ShowLocalizedMsg(IDS_ERR_CREATE_PATH, _T("log_dir"), o.log_dir);
    exit(1);
  }

  BuildFileList();
  if (!VerifyAutoConnections()) {
    exit(1);
  }
  GetProxyRegistrySettings();

#ifndef DISABLE_CHANGE_PASSWORD
  /* Initialize OpenSSL */
  OpenSSL_add_all_algorithms();
  ERR_load_crypto_strings();
#endif

  /* The Window structure */
  wincl.hInstance = hThisInstance;
  wincl.lpszClassName = szClassName;
  wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  wincl.cbSize = sizeof (WNDCLASSEX);

  /* Use default icon and mouse-pointer */
  wincl.hIcon = LoadLocalizedIcon(ID_ICO_APP);
  wincl.hIconSm = LoadLocalizedIcon(ID_ICO_APP);
  wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  wincl.lpszMenuName = NULL;                 /* No menu */
  wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  wincl.cbWndExtra = 0;                      /* structure or the window instance */
  /* Use Windows's default color as the background of the window */
  wincl.hbrBackground = (HBRUSH) COLOR_3DSHADOW; //COLOR_BACKGROUND;

  /* Register the window class, and if it fails quit the program */
  if (!RegisterClassEx (&wincl))
    return 1;

  /* The class is registered, let's create the program*/
  CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           szTitleText,         /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           (int)CW_USEDEFAULT,  /* Windows decides the position */
           (int)CW_USEDEFAULT,  /* where the window ends up on the screen */
           230,                 /* The programs width */
           200,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );


  /* Run the message loop. It will run until GetMessage() returns 0 */
  while (GetMessage (&messages, NULL, 0, 0))
  {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
  }

  /* The program return-value is 0 - The value that PostQuitMessage() gave */
  return messages.wParam;
}
Esempio n. 16
0
/*!
 * \brief Scan a list of directories recursively for music and albumart.
 *        Inserts, updates and removes any files any files found in the
 *        database.
 *
 * \param dirList List of directories to scan
 *
 * \returns Nothing.
 */
void MusicFileScanner::SearchDirs(const QStringList &dirList)
{
    QString host = gCoreContext->GetHostName();

    if (IsRunning())
    {
        // check how long the scanner has been running
        // if it's more than 60 minutes assume something went wrong
        QString lastRun =  gCoreContext->GetSetting("MusicScannerLastRunStart", "");
        if (!lastRun.isEmpty())
        {
            QDateTime dtLastRun = QDateTime::fromString(lastRun, Qt::ISODate);
            if (dtLastRun.isValid())
            {
                if (MythDate::current() > dtLastRun.addSecs(60*60))
                {
                    LOG(VB_GENERAL, LOG_INFO, "Music file scanner has been running for more than 60 minutes. Lets reset and try again");
                    gCoreContext->SendMessage(QString("MUSIC_SCANNER_ERROR %1 %2").arg(host).arg("Stalled"));

                    // give the user time to read the notification before restarting the scan
                    sleep(5);
                }
                else
                {
                    LOG(VB_GENERAL, LOG_INFO, "Music file scanner is already running");
                    gCoreContext->SendMessage(QString("MUSIC_SCANNER_ERROR %1 %2").arg(host).arg("Already_Running"));
                    return;
                }
            }
        }
    }

    //TODO: could sanity check the directory exists and is readable here?

    LOG(VB_GENERAL, LOG_INFO, "Music file scanner started");
    gCoreContext->SendMessage(QString("MUSIC_SCANNER_STARTED %1").arg(host));

    updateLastRunStart();
    QString status = QString("running");
    updateLastRunStatus(status);

    m_tracksTotal = m_tracksAdded = m_tracksUnchanged = m_tracksRemoved = m_tracksUpdated = 0;
    m_coverartTotal = m_coverartAdded = m_coverartUnchanged = m_coverartRemoved = m_coverartUpdated = 0;

    MusicLoadedMap music_files;
    MusicLoadedMap art_files;
    MusicLoadedMap::Iterator iter;

    for (int x = 0; x < dirList.count(); x++)
    {
        QString startDir = dirList[x];
        m_startDirs.append(startDir + '/');
        LOG(VB_GENERAL, LOG_INFO, QString("Searching '%1' for music files").arg(startDir));

        BuildFileList(startDir, music_files, art_files, 0);
    }

    m_tracksTotal = music_files.count();
    m_coverartTotal = art_files.count();

    ScanMusic(music_files);
    ScanArtwork(art_files);

    LOG(VB_GENERAL, LOG_INFO, "Updating database");

        /*
        This can be optimised quite a bit by consolidating all commands
        via a lot of refactoring.

        1) group all files of the same decoder type, and don't
        create/delete a Decoder pr. AddFileToDB. Or make Decoders be
        singletons, it should be a fairly simple change.

        2) RemoveFileFromDB should group the remove into one big SQL.

        3) UpdateFileInDB, same as 1.
        */

    for (iter = music_files.begin(); iter != music_files.end(); iter++)
    {
        if ((*iter).location == MusicFileScanner::kFileSystem)
            AddFileToDB(iter.key(), (*iter).startDir);
        else if ((*iter).location == MusicFileScanner::kDatabase)
            RemoveFileFromDB(iter.key(), (*iter).startDir);
        else if ((*iter).location == MusicFileScanner::kNeedUpdate)
        {
            UpdateFileInDB(iter.key(), (*iter).startDir);
            ++m_tracksUpdated;
        }
    }

    for (iter = art_files.begin(); iter != art_files.end(); iter++)
    {
        if ((*iter).location == MusicFileScanner::kFileSystem)
            AddFileToDB(iter.key(), (*iter).startDir);
        else if ((*iter).location == MusicFileScanner::kDatabase)
            RemoveFileFromDB(iter.key(), (*iter).startDir);
        else if ((*iter).location == MusicFileScanner::kNeedUpdate)
        {
            UpdateFileInDB(iter.key(), (*iter).startDir);
            ++m_coverartUpdated;
        }
    }

    // Cleanup orphaned entries from the database
    cleanDB();

    QString trackStatus = QString("total tracks found: %1 (unchanged: %2, added: %3, removed: %4, updated %5)")
                                  .arg(m_tracksTotal).arg(m_tracksUnchanged).arg(m_tracksAdded)
                                  .arg(m_tracksRemoved).arg(m_tracksUpdated);
    QString coverartStatus = QString("total coverart found: %1 (unchanged: %2, added: %3, removed: %4, updated %5)")
                                     .arg(m_coverartTotal).arg(m_coverartUnchanged).arg(m_coverartAdded)
                                     .arg(m_coverartRemoved).arg(m_coverartUpdated);


    LOG(VB_GENERAL, LOG_INFO, "Music file scanner finished ");
    LOG(VB_GENERAL, LOG_INFO, trackStatus);
    LOG(VB_GENERAL, LOG_INFO, coverartStatus);

    gCoreContext->SendMessage(QString("MUSIC_SCANNER_FINISHED %1 %2 %3 %4 %5")
                                      .arg(host).arg(m_tracksTotal).arg(m_tracksAdded)
                                      .arg(m_coverartTotal).arg(m_coverartAdded));

    updateLastRunEnd();
    status = QString("success - %1 - %2").arg(trackStatus).arg(coverartStatus);
    updateLastRunStatus(status);
}
Esempio n. 17
0
/*!
 * \brief Builds a list of all the files found descending recursively
 *        into the given directory
 *
 * \param directory Directory to begin search
 * \param music_files A pointer to the MusicLoadedMap to store the results
 * \param parentid The id of the parent directory in the music_directories
 *                 table. The root directory should have an id of 0
 *
 * \returns Nothing.
 */
void MusicFileScanner::BuildFileList(QString &directory, MusicLoadedMap &music_files, MusicLoadedMap &art_files, int parentid)
{
    QDir d(directory);

    if (!d.exists())
        return;

    d.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);

    QFileInfoList list = d.entryInfoList();
    if (list.isEmpty())
        return;

    QFileInfoList::const_iterator it = list.begin();
    const QFileInfo *fi;

    // Recursively traverse directory
    int newparentid = 0;
    while (it != list.end())
    {
        fi = &(*it);
        ++it;
        QString filename = fi->absoluteFilePath();
        if (fi->isDir())
        {

            QString dir(filename);
            dir.remove(0, m_startDirs.last().length());

            newparentid = m_directoryid[dir];

            if (newparentid == 0)
            {
                int id = GetDirectoryId(dir, parentid);
                m_directoryid[dir] = id;

                if (id > 0)
                {
                    newparentid = id;
                }
                else
                {
                    LOG(VB_GENERAL, LOG_ERR,
                        QString("Failed to get directory id for path %1")
                            .arg(dir));
                }
            }

            BuildFileList(filename, music_files, art_files, newparentid);
        }
        else
        {
            if (IsArtFile(filename))
            {
                MusicFileData fdata;
                fdata.startDir = m_startDirs.last();
                fdata.location = MusicFileScanner::kFileSystem;
                art_files[filename] = fdata;
            }
            else if (IsMusicFile(filename))
            {
                MusicFileData fdata;
                fdata.startDir = m_startDirs.last();
                fdata.location = MusicFileScanner::kFileSystem;
                music_files[filename] = fdata;
            }
            else
                LOG(VB_GENERAL, LOG_INFO,
                        QString("Found file with unsupported extension %1")
                            .arg(filename));
        }
    }
}
Esempio n. 18
0
int WINAPI WinMain (HINSTANCE hThisInstance,
UNUSED HINSTANCE hPrevInstance,
LPSTR lpszArgument,
UNUSED int nCmdShow)
{
	HWND hwnd;               /* This is the handle for our window */
	MSG messages;            /* Here messages to the application are saved */
	WNDCLASSEX wincl;        /* Data structure for the windowclass */
	HWND hwndAbout;
	DWORD shell32_version;


	/* initialize options to default state */
	init_options (&o);

#ifdef DEBUG
	/* Open debug file for output */
	if (!(o.debug_fp = fopen(DEBUG_FILE, "w")))
	{
		/* can't open debug file */
		ShowLocalizedMsg(GUI_NAME, ERR_OPEN_DEBUG_FILE, DEBUG_FILE);
		exit(1);
	}
	PrintDebug("Starting OpenVPN GUI v%s", GUI_VERSION);
#endif


	o.hInstance = hThisInstance;

	if(!GetModuleHandle("RICHED20.DLL"))
	{
		LoadLibrary("RICHED20.DLL");
	}
	else
	{
		/* can't load riched20.dll */
		ShowLocalizedMsg(GUI_NAME, ERR_LOAD_RICHED20, "");
		exit(1);
	}

	/* Check version of shell32.dll */
	shell32_version=GetDllVersion("shell32.dll");
	if (shell32_version < PACKVERSION(5,0))
	{
		/* shell32.dll version to low */
		ShowLocalizedMsg(GUI_NAME, ERR_SHELL_DLL_VERSION, shell32_version); 
		exit(1);
	}
#ifdef DEBUG
	PrintDebug("Shell32.dll version: 0x%lx", shell32_version);
#endif


	/* Parse command-line options */
	Createargcargv(&o, lpszArgument);

	/* Check if a previous instance is already running. */
	if ((FindWindow (szClassName, NULL)) != NULL)
	{
		/* GUI already running */
		ShowLocalizedMsg(GUI_NAME, ERR_GUI_ALREADY_RUNNING, "");
		exit(1);
	}
	
	if (!GetRegistryKeys()) {
		exit(1);
	}

#ifdef DEBUG
	PrintDebug("exe_path: %s", o.exe_path);
	PrintDebug("config_dir: %s", o.config_dir);
	PrintDebug("log_dir: %s", o.log_dir);
	PrintDebug("priority_string: %s", o.priority_string);
	PrintDebug("append_string: %s", o.append_string);
	PrintDebug("log_viewer: %s", o.log_viewer);
	PrintDebug("editor: %s", o.editor);
	PrintDebug("allow_edit: %s", o.allow_edit);
	PrintDebug("allow_service: %s", o.allow_service);
	PrintDebug("allow_password: %s", o.allow_password);
	PrintDebug("allow_proxy: %s", o.allow_proxy);
	PrintDebug("silent_connection: %s", o.silent_connection);
	PrintDebug("service_only: %s", o.service_only);
	PrintDebug("show_balloon: %s", o.show_balloon);
	PrintDebug("show_script_window: %s", o.show_script_window);
	PrintDebug("psw_attempts_string: %s", o.psw_attempts_string);
	PrintDebug("disconnect_on_suspend: %s", o.disconnect_on_suspend);
	PrintDebug("connectscript_timeout_string: %s", o.connectscript_timeout_string);
	PrintDebug("disconnectscript_timeout_string: %s", o.disconnectscript_timeout_string);
	PrintDebug("preconnectscript_timeout_string: %s", o.preconnectscript_timeout_string);
#endif

	if (!CheckVersion()) {
		exit(1);
	}
	if (!BuildFileList()) {
		exit(1);
	}
	if (!VerifyAutoConnections()) {
		exit(1);
	}
	GetProxyRegistrySettings();

#ifndef DISABLE_CHANGE_PASSWORD
	/* Initialize OpenSSL */
	OpenSSL_add_all_algorithms();
	ERR_load_crypto_strings();
#endif

	/* The Window structure */
	wincl.hInstance = hThisInstance;
	wincl.lpszClassName = szClassName;
	wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
	wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
	wincl.cbSize = sizeof (WNDCLASSEX);

	/* Use default icon and mouse-pointer */
	wincl.hIcon = LoadIcon (hThisInstance, MAKEINTRESOURCE(APP_ICON));
	wincl.hIconSm = LoadIcon (hThisInstance, MAKEINTRESOURCE(APP_ICON));
	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
	wincl.lpszMenuName = NULL;                 /* No menu */
	wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
	wincl.cbWndExtra = 0;                      /* structure or the window instance */
	/* Use Windows's default color as the background of the window */
	wincl.hbrBackground = (HBRUSH) COLOR_3DSHADOW; //COLOR_BACKGROUND;

	/* Register the window class, and if it fails quit the program */
	if (!RegisterClassEx (&wincl))
	return 1;

	/* The class is registered, let's create the program*/
	hwnd = CreateWindowEx (
	0,                   /* Extended possibilites for variation */
	szClassName,         /* Classname */
	szTitleText,         /* Title Text */
	WS_OVERLAPPEDWINDOW, /* default window */
	(int)CW_USEDEFAULT,  /* Windows decides the position */
	(int)CW_USEDEFAULT,  /* where the window ends up on the screen */
	230,                 /* The programs width */
	200,                 /* and height in pixels */
	HWND_DESKTOP,        /* The window is a child-window to desktop */
	NULL,                /* No menu */
	hThisInstance,       /* Program Instance handler */
	NULL                 /* No Window Creation data */
	);


	/* Run the message loop. It will run until GetMessage() returns 0 */
	while (GetMessage (&messages, NULL, 0, 0))
	{
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}

	/* The program return-value is 0 - The value that PostQuitMessage() gave */
	return messages.wParam;
}