Esempio n. 1
0
bool QBattSysFSMethod::searchSysFs_Battery()
{
	QDir searchDir(PSU_SYSTEM_PATH);
	QString path;

	if (!checkDirExists(PSU_SYSTEM_PATH))
		return false;

	searchDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
	QDirIterator qdi(searchDir, QDirIterator::Subdirectories);

	while (qdi.hasNext()) {
		path = qdi.next();
		if (!(QString::compare(getFileContents(path, PSU_FILE_TYPE),
							   DEF_BATTERY_TYPE, Qt::CaseSensitive))) {
			psu->battery.path = path;
			return true;
		}
	}

	// Initialize path with "none"
	psu->battery.path = PSU_SYSTEM_PATH_NONE;

	return false;
}
Esempio n. 2
0
QString QBattSysFSMethod::getFileContents(QString fpath, QString fname)
{
	QString path;
	QString result;

	if (!checkDirExists(fpath))
		return RESPONSE_N_A;

	path.append(fpath);
	path.append('/');
	path.append(fname);

	QFile file(path);

	if (file.open(QIODevice::ReadOnly)) {
		char buf[256];
		qint64 lineLength = file.readLine(buf, sizeof(buf));
		if (lineLength != -1) {
			result = QString(buf);
			file.close();

			return result.trimmed();
		}
	}

	return RESPONSE_N_A;
}
Esempio n. 3
0
//--------------------------------------------------------------
void saverScene::update(float mouseX, float mouseY){

	saveAndUpload.setMaxCounter(buttonCount);
	clearTags.setMaxCounter(buttonCount*2);	
	
	mx = mouseX;
	my = mouseY;

	if( saveAndUpload.update(mx, my) ){
		
		checkDirExists();
		
		string timeStr = ofGetTimestampString();
        
		
		string fileName = "temptTag-"+timeStr+".gml";
		
		string fullPath = "tags/gml/"+fileName;
		
		imagePath	    = "tags/images/";
		imageFilename   = "temptTag-"+timeStr+".png";
		
		//add the file name to gml
    /*  gml.saveStateAndFileName(groups.getVector(), fullPath, fileName);
				
		reader.loadGML(fullPath);
		
		if( bUpload )uploader.uploadToWeb(gmlUploadString, reader.xml);
		if( bUpload )grabScreen = true;
     */
	}
	
	if( tmpGroups.size() ){
		if( addTag.update(mx, my) ){
			vector <strokeGroup> & vec = groups.getVector();
			for(int i = 0; i < tmpGroups.size(); i++){
				vec.push_back(tmpGroups[i]);
			}
			tmpGroups.clear();
		}
		if( clearLoaded.update(mx, my) ){
			tmpGroups.clear();
		}
	}
	
	if( loadNext.update(mx, my) ){
		loadNextState();
	}
	
	if( loadPrevious.update(mx, my) ){
		loadPreState();
	}
		
	if( clearTags.update(mx, my) ){
		groups.clear();
		groups.addGroup();	
	}
	
}
Esempio n. 4
0
bool QBattSysFSMethod::checkFileExists(QString fpath, QString fname)
{
	QString path;

	if (!checkDirExists(fpath))
		return false;

	path.append(fpath);
	path.append('/');
	path.append(fname);

	QFile file(path);

	return file.exists();
}
Esempio n. 5
0
void createDirectory(const char* dir)
{
    if (dir && *dir)
    {
        if (!checkDirExists(dir)) {
#ifdef WIN32
            if (mkdir(dir)!=0)
#else
            if (mkdir(dir,0755)!=0)
#endif
            {
                fprintf(stderr,"Create directory %s failed", dir);
                exit(1);
            }
        }
    }
}
Esempio n. 6
0
File: dirs.cpp Progetto: TRI0N/wwiv
void checkFileAreas(const std::string& datadir, bool verbose) {
  vector<directoryrec> directories;
  {
    DataFile<directoryrec> file(datadir, DIRS_DAT);
    if (!file) {
      // TODO(rushfan): show error?
      return;
    }
    if (!file.ReadVector(directories)) {
      // TODO(rushfan): show error?
      return;
    }
  }

  LOG(INFO) << "Checking " << directories.size() << " directories.";
  for (size_t i = 0; i < directories.size(); i++) {
    if (!(directories[i].mask & mask_cdrom) && !(directories[i].mask & mask_offline)) {
      File dir(directories[i].path);
      if (checkDirExists(dir, directories[i].name)) {
        LOG(INFO) << "Checking directory: " << directories[i].name;
        string filename = StrCat(directories[i].filename, ".dir");
        File recordFile(datadir, filename);
        if (recordFile.Exists()) {
          if (!recordFile.Open(File::modeReadWrite | File::modeBinary)) {
            LOG(INFO) << "Unable to open:" << recordFile.full_pathname();
          } else {
            unsigned int numFiles = recordFile.GetLength() / sizeof(uploadsrec);
            uploadsrec upload;
            recordFile.Read(&upload, sizeof(uploadsrec));
            if (upload.numbytes != numFiles) {
              LOG(INFO) << "Corrected # of files in: " << directories[i].name;
              upload.numbytes = numFiles;
              recordFile.Seek(0L, File::seekBegin);
              recordFile.Write(&upload, sizeof(uploadsrec));
            }
            if (numFiles >= 1) {
              ext_desc_rec *extDesc = nullptr;
              unsigned int recNo = 0;
              string filenameExt = directories[i].filename;
              filenameExt.append(".ext");
              File extDescFile(datadir, filenameExt);
              if (extDescFile.Exists()) {
                if (extDescFile.Open(File::modeReadWrite | File::modeBinary)) {
                  extDesc = (ext_desc_rec *)malloc(numFiles * sizeof(ext_desc_rec));
                  size_t offs = 0;
                  while (offs < (unsigned long)extDescFile.GetLength() && recNo < numFiles) {
                    ext_desc_type ed;
                    extDescFile.Seek(offs, File::seekBegin);
                    if (extDescFile.Read(&ed, sizeof(ext_desc_type)) == sizeof(ext_desc_type)) {
                      strcpy(extDesc[recNo].name, ed.name);
                      extDesc[recNo].offset = offs;
                      offs += ed.len + sizeof(ext_desc_type);
                      recNo++;
                    }
                  }
                }
                extDescFile.Close();
              }
              for (size_t fileNo = 1; fileNo < numFiles; fileNo++) {
                bool modified = false;
                recordFile.Seek(sizeof(uploadsrec) * fileNo, File::seekBegin);
                recordFile.Read(&upload, sizeof(uploadsrec));
                bool extDescFound = false;
                for (unsigned int desc = 0; desc < recNo; desc++) {
                  if (strcmp(upload.filename, extDesc[desc].name) == 0) {
                    extDescFound = true;
                  }
                }
                if (extDescFound && ((upload.mask & mask_extended) == 0)) {
                  upload.mask |= mask_extended;
                  modified = true;
                  LOG(INFO) << "Fixed (added) extended description for: " << upload.filename;
                } else if (!extDescFound && (upload.mask & mask_extended)) {
                  upload.mask &= ~mask_extended;
                  modified = true;
                  LOG(INFO) << "Fixed (removed) extended description for: " << upload.filename;
                }
                File file(directories[i].path, Unalign(upload.filename));
                if (strlen(upload.filename) > 0 && file.Exists()) {
                  if (file.Open(File::modeReadOnly | File::modeBinary)) {
                    if (verbose) {
                      LOG(INFO) << "Checking file: " << file.full_pathname();
                    }
                    if (upload.numbytes != (unsigned long)file.GetLength()) {
                      upload.numbytes = file.GetLength();
                      modified = true;
                      LOG(INFO) << "Fixed file size for: " << upload.filename;
                    }
                    file.Close();
                  } else {
                    LOG(INFO) << "Unable to open file '" << file.full_pathname()
                      << "', error:" << file.GetLastError();
                  }
								}
								if (modified) {
									recordFile.Seek(sizeof(uploadsrec) * fileNo, File::seekBegin);
									recordFile.Write(&upload, sizeof(uploadsrec));
								}
							}
							if (extDesc != nullptr) {
								free(extDesc);
                extDesc = nullptr;
							}
						}
						recordFile.Close();
					}
				} else {
          LOG(INFO) << "Directory '" << directories[i].name
            << "' missing file: " << recordFile.full_pathname();
				}
			}
		} else if (directories[i].mask & mask_offline) {
      LOG(INFO) << "Skipping directory '" << directories[i].name << "' [OFFLINE]";
		} else if (directories[i].mask & mask_cdrom) {
      LOG(INFO) << "Skipping directory '" << directories[i].name << "' [CDROM]";
		} else {
      LOG(INFO) << "Skipping directory '" << directories[i].name << "' [UNKNOWN MASK]";
		}
	}
}
Esempio n. 7
0
int main(int argc,char **argv) 
{
    InitModuleObjects();
    EnableSEHtoExceptionMapping();
#ifndef __64BIT__
    Thread::setDefaultStackSize(0x10000);   // 64K stack (also set in windows DSP)
#endif

    StringBuffer logDir;
#ifdef _WIN32
    logDir.append("c:\\");
#else
    if (checkDirExists("/c$"))
        logDir.append("/c$/");
#endif

    Owned<IFile> sentinelFile = createSentinelTarget();
    removeSentinelFile(sentinelFile);

    SocketEndpoint listenep;
    unsigned sendbufsize = 0;
    unsigned recvbufsize = 0;
    int i = 1;
    bool isdaemon = (memicmp(argv[0]+strlen(argv[0])-4,".exe",4)==0);
    // bit of a kludge for windows - if .exe not specified then not daemon
    bool locallisten = false;
    const char *logdir=NULL;
    bool requireauthenticate = false;
    while (argc>i) {
        if (stricmp(argv[i],"-D")==0) {
            i++;
            isdaemon = true;
        }
        else if (stricmp(argv[i],"-R")==0) { // for remote run
            i++;
#ifdef _WIN32
            isdaemon = false;
#else
            isdaemon = true;
#endif
        }
        else if (stricmp(argv[i],"-A")==0) { 
            i++;
            requireauthenticate = true;
        }
        else if ((argv[i][0]=='-')&&(toupper(argv[i][1])=='T')&&(!argv[i][2]||isdigit(argv[i][2]))) {
            if (argv[i][2])
                setDafsTrace(NULL,(byte)atoi(argv[i]+2));
            i++;
            isdaemon = false;
        }
        else if ((argc>i+1)&&(stricmp(argv[i],"-L")==0)) { 
            i++;
            logDir.clear().append(argv[i++]);
            addPathSepChar(logDir);
        }
        else if (stricmp(argv[i],"-LOCAL")==0) { 
            i++;
            locallisten = true;
        }
        else
            break;
    }

#ifdef _WIN32
    if ((argc>i)&&(stricmp(argv[i],"-install")==0)) {
        if (installService(DAFS_SERVICE_NAME,DAFS_SERVICE_DISPLAY_NAME,NULL)) {
            PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Installed");
            return 0;
        }
        return 1;
    }
    if ((argc>i)&&(stricmp(argv[i],"-remove")==0)) {
        if (uninstallService(DAFS_SERVICE_NAME,DAFS_SERVICE_DISPLAY_NAME)) {
            PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Uninstalled");
            return 0;
        }
        return 1;
    }
#endif
    if (argc == i)
      listenep.port = DAFILESRV_PORT;
    else {
        if (strchr(argv[i],'.')||!isdigit(argv[i][0]))
            listenep.set(argv[i],DAFILESRV_PORT);
        else
            listenep.port = atoi(argv[i]);
        if (listenep.port==0) {
            usage();
            exit(-1);
        }
        sendbufsize = (argc>i+1)?(atoi(argv[i+1])*1024):0;
        recvbufsize = (argc>i+2)?(atoi(argv[i+2])*1024):0;
    }
    if (isdaemon) {
#ifdef _WIN32
        class cserv: public CService
        {
            bool stopped;
            bool started;
            SocketEndpoint listenep;
            bool requireauthenticate;

            
            class cpollthread: public Thread
                
            {
                cserv *parent;
            public:
                cpollthread( cserv *_parent ) 
                : Thread("CService::cpollthread"), parent(_parent) 
                {
                }
                int run() 
                { 
                    while (parent->poll())
                        Sleep(1000);
                    return 1;
                }
            } pollthread;
            Owned<IRemoteFileServer> server;

        public:

            cserv(SocketEndpoint _listenep) 
                : listenep(_listenep),pollthread(this)
            {
                stopped = false;
                started = false;
            }

            virtual ~cserv()
            {
                stopped = true;
                if (started)
                    pollthread.join();
            }

            bool init()
            {
                PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Initialized");
                started = true;
                pollthread.start();
                return true;
            }

            bool poll()
            {
                if (stopped||!running()) {
                    PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Stopping");
                    if (server) {
                        server->stop();
                        server.clear();
                    }
                    return false;
                }
                return true;
            }

            void run()
            {
                // Get params from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DaFileSrv\Parameters
                
                int requireauthenticate=0;
                HKEY hkey;
                if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                                 "SYSTEM\\CurrentControlSet\\Services\\DaFileSrv\\Parameters",
                                 0,
                                 KEY_QUERY_VALUE,
                                 &hkey) == ERROR_SUCCESS) {
                    DWORD dwType = 0;
                    DWORD dwSize = sizeof(requireauthenticate);
                    RegQueryValueEx(hkey,
                                    "RequireAuthentication",
                                    NULL,
                                    &dwType,
                                    (BYTE*)&requireauthenticate,
                                    &dwSize);
                    RegCloseKey(hkey);
                }
                StringBuffer eps;
                if (listenep.isNull())
                    eps.append(listenep.port);
                else
                    listenep.getUrlStr(eps);
                enableDafsAuthentication(requireauthenticate!=0);
                PROGLOG("Opening "DAFS_SERVICE_DISPLAY_NAME" on %s", eps.str());
                const char * verstring = remoteServerVersionString();
                PROGLOG("Version: %s", verstring);
                PROGLOG("Authentication:%s required",requireauthenticate?"":" not");
                PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Running");
                server.setown(createRemoteFileServer());
                try {
                    server->run(listenep);
                }
                catch (IException *e) {
                    EXCLOG(e,DAFS_SERVICE_NAME);
                    e->Release();
                }
                PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Stopped");
                stopped = true;
            }
        } service(listenep);
        service.start();
        return 0;
#else
        int ret = initDaemon();
        if (ret)
            return ret;
#endif
    }
    {
        Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(logDir.str(), "DAFILESRV");
        lf->setCreateAliasFile(false);
        lf->setMaxDetail(TopDetail);
        lf->beginLogging();
    }
    const char * verstring = remoteServerVersionString();
    StringBuffer eps;
    if (listenep.isNull())
        eps.append(listenep.port);
    else
        listenep.getUrlStr(eps);
    enableDafsAuthentication(requireauthenticate);
    PROGLOG("Opening Dali File Server on %s", eps.str());
    PROGLOG("Version: %s", verstring);
    PROGLOG("Authentication:%s required",requireauthenticate?"":" not");
    startPerformanceMonitor(10*60*1000, PerfMonStandard);
    server.setown(createRemoteFileServer());
    writeSentinelFile(sentinelFile);
    try {
        server->run(listenep);
    }
    catch (IException *e) {
        EXCLOG(e,"DAFILESRV");
        e->Release();
    }
    if (server)
        server->stop();
    server.clear();
    PROGLOG("Stopped Dali File Server");

    return 0;
}