Ejemplo n.º 1
0
bool cPluginMhp::Initialize(void)
{
   // Initialize any background activities the plugin shall perform.
   
/*
   //VDR loads plugins without the RTDL_GLOBAL flag in dlopen.
   //Dynamic modules dlopen'ed by the plugin, however, will link against symbols from
   //the plugin itself, so it is necessary to reload its symbols globally.
   //Needed by the MHPOutput module and Java native libraries.
   char *buffer = NULL;
   //from vdr/plugin.c
   asprintf(&buffer, "%s/%s%s%s%s", VDRPluginPath, LIBVDR_PREFIX, "mhp", SO_INDICATOR, VDRVERSION);
   if (!ownPlugin.Load(buffer)) {
      esyslog("MHP: Failed to re-open own dynamic object (this plugin)."
              "Remember to give the plugin the same \"-L\" option as VDR!");
      printf("MHP: Failed to re-dlopen the dynamic object of this plugin.\n"
             "You have to give the plugin the same \"-L\" option as you specified on the command line for VDR!\n");
      return false;
   }
   free(buffer);
*/

   InitializeLocalApps();
   
   if (Mhp::ConfigPath==0) {
      char *c;
      asprintf(&c, "%s%s", VideoDirectory, "/mhp");
      Mhp::ConfigPath=c;
   }
   MakeDirs(Mhp::ConfigPath, true);
   if (!DirectoryOk(Mhp::ConfigPath, true))
      esyslog("MHP: Config directory is not accessible. Settings will not be stored.");
   
   return true;
}
Ejemplo n.º 2
0
bool cCutter::Start(const char *FileName)
{
  if (!cuttingThread) {
     error = false;
     ended = false;
     cRecording Recording(FileName);
     
     cMarks FromMarks;
     FromMarks.Load(FileName);
     cMark *First=FromMarks.First();
     if (First) Recording.SetStartTime(Recording.start+((First->position/FRAMESPERSEC+30)/60)*60);
     
     const char *evn = Recording.PrefixFileName('%');
     if (evn && RemoveVideoFile(evn) && MakeDirs(evn, true)) {
        // XXX this can be removed once RenameVideoFile() follows symlinks (see videodir.c)
        // remove a possible deleted recording with the same name to avoid symlink mixups:
        char *s = strdup(evn);
        char *e = strrchr(s, '.');
        if (e) {
           if (strcmp(e, ".rec") == 0) {
              strcpy(e, ".del");
              RemoveVideoFile(s);
              }
           }
        free(s);
        // XXX
        editedVersionName = strdup(evn);
        Recording.WriteInfo();
        Recordings.AddByName(editedVersionName, false);
        cuttingThread = new cCuttingThread(FileName, editedVersionName);
        return true;
        }
     }
  return false;
}
Ejemplo n.º 3
0
bool cLiveRecorder::Prepare() {
	if (!MakeDirs(FileName(), true)) return false;
	if (!Cleanup()) return false;
	int DiskSize = DiskSizeMB(FileName());
	if (DiskSize < ((BufferDirectoryMinFree?BufferDirectoryMinFree:MINFREEDISKSPACE)+MINLIVEBUFFERSIZE)) return false;  
	return true;
}; // cLiveRecorder::Prepare
Ejemplo n.º 4
0
bool sprawl::filesystem::Renames(sprawl::String const& path, String const& newName)
{
	if(!MakeDirs(path::Dirname(newName), 0777))
	{
		return false;
	}
	return Rename(path, newName);
}
Ejemplo n.º 5
0
void Storage::prepareDirectory(tChannelID chan) {
   currentDir = cString::sprintf("%s/%s", root, *chan.ToString());
   if (!MakeDirs(currentDir, 1)) {
      esyslog("OSD-Teletext: Error preparing directory for channel \"%s\"",
              *chan.ToString());
      return;
   }
   failedFreeSpace=false;
}
Ejemplo n.º 6
0
const char *cPlugin::ConfigDirectory(const char *PluginName)
{
  static char *buffer = NULL;
  if (!cThread::IsMainThread())
     esyslog("ERROR: plugin '%s' called cPlugin::ConfigDirectory(), which is not thread safe!", PluginName ? PluginName : "<no name given>");
  free(buffer);
  asprintf(&buffer, "%s/plugins%s%s", configDirectory, PluginName ? "/" : "", PluginName ? PluginName : "");
  return MakeDirs(buffer, true) ? buffer : NULL;
}
Ejemplo n.º 7
0
CPLErr GDALWMSCache::Write(const char *key, const CPLString &file_name) {
    CPLString cache_file(KeyToCacheFile(key));
    //	printf("GDALWMSCache::Write(%s, %s) -> %s\n", key, file_name.c_str());
    if (CPLCopyFile(cache_file.c_str(), file_name.c_str()) != CE_None) {
        MakeDirs(cache_file.c_str());
        CPLCopyFile(cache_file.c_str(), file_name.c_str());
    }

    return CE_None;
}
Ejemplo n.º 8
0
cDBusOsd::cDBusOsd(cDBusOsdProvider& Provider, int Left, int Top, uint Level)
 :cOsd(Left, Top, Level)
 ,provider(Provider)
 ,osd_index(osd_number++)
 ,counter(0)
{
  osd_dir = cString::sprintf("%s/dbusosd-%04x", DBUSOSDDIR, osd_index);
  if (!MakeDirs(*osd_dir, true))
     esyslog("dbus2vdr: can't create %s", *osd_dir);
  provider.SendMessage(new cDbusOsdMsg("Open", osd_dir, Left, Top, 0, 0));
}
Ejemplo n.º 9
0
BOOL CRTFolder::MakeDirs(LPCTSTR lpPathName)
{
	if(CreateDirectory(lpPathName,NULL))
		return TRUE;

	char buf[MAX_PATH];
	GetFilePath(lpPathName,buf);
	if(!MakeDirs(buf))
		return FALSE;
	if(CreateDirectory(lpPathName,NULL))
		return TRUE;
	else
		return FALSE;
}
Ejemplo n.º 10
0
void cThemes::SetThemesDirectory(const char *ThemesDirectory)
{
  free(themesDirectory);
  themesDirectory = strdup(ThemesDirectory);
  MakeDirs(themesDirectory, true);
}
Ejemplo n.º 11
0
LOCAL_C void TestDirs()
//
// Scan directories and files with DC on, so only the root \Private
// and \System directories should be found (no contents).
//
	{

	MakeDirs();
	ListDirs();

	CDirScan* scanner = NULL;
	TInt r;
	TRAP(r, scanner = CDirScan::NewL(TheFs));
	test_Value(r, r == KErrNone && scanner);
	TParse dirName;
	TheFs.Parse(_L("\\"),dirName);
	TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
	test_KErrNone(r);
	CDir *entryList = NULL;
	TInt  num = 0;
	test.Printf(_L("------ ACCESSIBLE DIRECTORIES ------\n"));
	for (;;)
		{
		TRAP(r, scanner->NextL(entryList));
		if (r != KErrNone)
			{
			test.Printf(_L("*** ERROR %d doing NextL()\n"), r);
			break;
			}
		if (entryList==NULL)
			break;
		TInt count=entryList->Count();
		while (count--)
			{
			TEntry data=(*entryList)[count];
			TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
			path.Append(data.iName);
			if (path == gDirList[num])
				{
				test.Printf(_L("%S\n"),&path);
				num++;
				}
			else
				{
				test.Printf(_L("%S *** NOT FOUND ***\n"),&path);
				}
			}
		delete entryList;
		entryList=NULL;
		}
	delete scanner;
	CleanDirs();
	test_KErrNone(r);
	if (num < gDirNum)
		{
		test.Printf(_L("Directory not as expected (%d found < %d expected\n"), num, gDirNum);
		test(0);
		}
	test.Printf(_L("------------------------------------\n"));

	}
Ejemplo n.º 12
0
bool HardLinkVideoFile(const char *OldName, const char *NewName)
{
  // Incoming name must be in base video directory:
  if (strstr(OldName, VideoDirectory) != OldName) {
     esyslog("ERROR: %s not in %s", OldName, VideoDirectory);
     return false;
     }
  if (strstr(NewName, VideoDirectory) != NewName) {
     esyslog("ERROR: %s not in %s", NewName, VideoDirectory);
     return false;
     }

  const char *ActualNewName = NewName;
  cString ActualOldName(ReadLink(OldName), true);

  // Some safety checks:
  struct stat StatOldName;
  if (lstat(ActualOldName, &StatOldName) == 0) {
     if (S_ISLNK(StatOldName.st_mode)) {
        esyslog("HardLinkVideoFile: Failed to resolve symbolic link %s", (const char*)ActualOldName);
        return false;
        }
     }
  else {
     esyslog("HardLinkVideoFile: lstat failed on %s", (const char*)ActualOldName);
     return false;
     }
  isyslog("HardLinkVideoFile: %s is on %i", (const char*)ActualOldName, (int)StatOldName.st_dev);

  // Find the video directory where ActualOldName is located

  cVideoDirectory Dir;
  struct stat StatDir;
  if (!StatNearestDir(NewName, &StatDir)) {
     esyslog("HardLinkVideoFile: stat failed on %s", NewName);
     return false;
     }

  isyslog("HardLinkVideoFile: %s is on %i", NewName, (int)StatDir.st_dev);
  if (StatDir.st_dev != StatOldName.st_dev) {
     // Not yet found.

     if (!Dir.IsDistributed()) {
        esyslog("HardLinkVideoFile: No matching video folder to hard link %s", (const char*)ActualOldName);
        return false;
        }

     // Search in video01 and upwards
     bool found = false;
     while (Dir.Next()) {
        Dir.Store();
        const char *TmpNewName = Dir.Adjust(NewName);
        if (StatNearestDir(TmpNewName, &StatDir) && StatDir.st_dev == StatOldName.st_dev) {
           isyslog("HardLinkVideoFile: %s is on %i (match)", TmpNewName, (int)StatDir.st_dev);
           ActualNewName = TmpNewName;
           found = true;
           break;
           }
        isyslog("HardLinkVideoFile: %s is on %i", TmpNewName, (int)StatDir.st_dev);
        }
     if (ActualNewName == NewName) {
        esyslog("HardLinkVideoFile: No matching video folder to hard link %s", (const char*)ActualOldName);
        return false;
        }

     // Looking good, we have a match. Create necessary folders.
     if (!MakeDirs(ActualNewName, false))
        return false;
     // There's no guarantee that the directory of ActualNewName
     // is on the same device as the dir that StatNearestDir found.
     // But worst case is that the link fails.
     }

#ifdef HARDLINK_TEST_ONLY
  // Do the hard link to *.vdr_ for testing only
  char *name = NULL;
  asprintf(&name, "%s_",ActualNewName);
  link(ActualOldName, name);
  free(name);
  return false;
#endif // HARDLINK_TEST_ONLY

  // Try creating the hard link
  if (link(ActualOldName, ActualNewName) != 0) {
     // Failed to hard link. Maybe not allowed on file system.
     LOG_ERROR_STR(ActualNewName);
     isyslog("HardLinkVideoFile: failed to hard link from %s to %s", (const char*)ActualOldName, ActualNewName);
     return false;
     }

  if (ActualNewName != NewName) {
     // video01 and up. Do the remaining symlink
     if (symlink(ActualNewName, NewName) < 0) {
        LOG_ERROR_STR(NewName);
        return false;
        }
     }
  return true;
}
Ejemplo n.º 13
0
cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags)
{
  const char *ActualFileName = FileName;

  // Incoming name must be in base video directory:
#ifdef USE_LIVEBUFFER
  if ((strstr(FileName, VideoDirectory ) != FileName) &&
      (strstr(FileName, BufferDirectory) != FileName)) {
#else
  if (strstr(FileName, VideoDirectory) != FileName) {
#endif /*USE_LIVEBUFFER*/
     esyslog("ERROR: %s not in %s", FileName, VideoDirectory);
     errno = ENOENT; // must set 'errno' - any ideas for a better value?
     return NULL;
     }
  // Are we going to create a new file?
  if ((Flags & O_CREAT) != 0) {
     cVideoDirectory Dir;
     if (Dir.IsDistributed()) {
#ifdef USE_DVLVIDPREFER
        if (Setup.UseVidPrefer == 0) {
#endif /* DVLVIDPREFER */
        // Find the directory with the most free space:
        int MaxFree = Dir.FreeMB();
        while (Dir.Next()) {
              int Free = FreeDiskSpaceMB(Dir.Name());
              if (Free > MaxFree) {
                 Dir.Store();
                 MaxFree = Free;
                 }
              }
#ifdef USE_DVLVIDPREFER
        }
          else Dir.GetPreferedVideoDir();
#endif /* DVLVIDPREFER */
        if (Dir.Stored()) {
           ActualFileName = Dir.Adjust(FileName);
           if (!MakeDirs(ActualFileName, false))
              return NULL; // errno has been set by MakeDirs()
#ifdef USE_DVLVIDPREFER
           if (strcmp(ActualFileName, FileName) != 0) {
#endif /* DVLVIDPREFER */
           if (symlink(ActualFileName, FileName) < 0) {
              LOG_ERROR_STR(FileName);
              return NULL;
              }
#ifdef USE_DVLVIDPREFER
              }
#endif /* DVLVIDPREFER */
           ActualFileName = strdup(ActualFileName); // must survive Dir!
           }
        }
     }
  cUnbufferedFile *File = cUnbufferedFile::Create(ActualFileName, Flags, DEFFILEMODE);
  if (ActualFileName != FileName)
     free((char *)ActualFileName);
  return File;
}

int CloseVideoFile(cUnbufferedFile *File)
{
  int Result = File->Close();
  delete File;
  return Result;
}
Ejemplo n.º 14
0
void mhmakefileparser::SaveAutoDepsFile()
{
  if (!IsAutoDepsDirty())
    return;

  if (g_Clean
#ifdef _DEBUG
      || g_DoNotExecute || g_GenProjectTree
#endif
     )
    return;   // do not save on clean or if no commands are executed

  string DepFile=ExpandVar(AUTODEPFILE);
  if (!DepFile.size())
  {
    return;
  }
  fileinfo *pDepFile=GetFileInfo(DepFile,m_MakeDir);

#ifdef _DEBUG
  if (g_PrintAdditionalInfo)
    cout<<"Saving automatic dependency file "<<DepFile<<endl;
#endif

  FILE *pOut=fopen(pDepFile->GetFullFileName().c_str(),"wb");
  if (!pOut)
  {
    /* Maybe it is because the directory does not exist, so try to create this first */
    if (!MakeDirs(pDepFile->GetDir()))
    {
      #ifdef _DEBUG
      if (!g_DoNotExecute)
      #endif
        cerr << "Error creating dir "<<pDepFile->GetDir()->GetFullFileName()<<endl;
      return;
    }
    pOut=fopen(pDepFile->GetFullFileName().c_str(),"wb");

    if (!pOut)
    {
      #ifdef _DEBUG
      if (!g_DoNotExecute)
      #endif
        cerr << "Error creating file "<<DepFile<<endl;
      return;
    }
  }
  // First update the USER_ENVVARS variable and then save it to the dep file together with the md5 string
  CreateUSED_ENVVARS();
  uint32 Md5_32=CreateEnvMd5_32();
  fwrite(&Md5_32,sizeof(Md5_32),1,pOut);
  fprintf(pOut,"%s\n",m_Variables[USED_ENVVARS].c_str());

  autodeps_t::const_iterator It=m_AutoDeps.begin();
  while (It!=m_AutoDeps.end())
  {
    if (!It->second.second.empty())
    {
      fprintf(pOut,"%s\n",It->first->GetFullFileName().c_str());
      deps_t::const_iterator DepIt=It->second.second.begin();
      while (DepIt!=It->second.second.end())
      {
        fprintf(pOut,"%s\n",(*DepIt)->GetFullFileName().c_str());
        DepIt++;
      }
      fprintf(pOut,"\n");
    }
    It++;
  }
  /* Now save the Md5 strings */
  fprintf(pOut,"\n");

  set<const fileinfo *>::iterator pIt=m_Targets.begin();
  while (pIt!=m_Targets.end())
  {
    if (!(*pIt)->CompareMd5_32(0))
    {
      (*pIt)->WriteMd5_32(pOut);
      string FileName=(*pIt)->GetFullFileName();
      fwrite(FileName.c_str(),FileName.size(),1,pOut);
      fputc('\n',pOut);
    }
    pIt++;
  }

  fclose(pOut);
}