Exemple #1
0
int CutTxtMain(TCHAR *file_name)
{
	FileEx src_file(file_name);
	if (src_file.Open())
	{
		DWORD rw = 0;
		LONGLONG ptr = 0;
		BYTE r_buff[BLOCK_SIZE] = {0};
		STATISTIC statistic;

		while (rw = src_file.Read(r_buff, BLOCK_SIZE))
		{
			AnalyzeBuffer(r_buff, rw, statistic);
			if (IsPartOfTextFile(statistic))
			{
				SaveToFile(src_file, ptr);
			}

			src_file.GetPointer(&ptr);
			_tprintf(_T("LBA: %I64d\n"), ptr/BLOCK_SIZE);
		}

		return 0;
	}
	return -1;
}
Exemple #2
0
      inline bool copy_file(const std::string& src_file_name, const std::string& dest_file_name)
      {
         std::ifstream src_file(src_file_name.c_str(),std::ios::binary);
         std::ofstream dest_file(dest_file_name.c_str(),std::ios::binary);
         if (!src_file) return false;
         if (!dest_file) return false;

         const std::size_t block_size = 1024;
         char buffer[block_size];

         std::size_t remaining_bytes = file_size(src_file_name);

         while (remaining_bytes >= block_size)
         {
            src_file.read(&buffer[0],static_cast<std::streamsize>(block_size));
            dest_file.write(&buffer[0],static_cast<std::streamsize>(block_size));
            remaining_bytes -= block_size;
         }

         if (remaining_bytes > 0)
         {
            src_file.read(&buffer[0],static_cast<std::streamsize>(remaining_bytes));
            dest_file.write(&buffer[0],static_cast<std::streamsize>(remaining_bytes));
            remaining_bytes = 0;
         }

         src_file.close();
         dest_file.close();

         return true;
      }
Exemple #3
0
static std::string readFile(const char *file)
{
  std::ifstream       src_file(file);
  std::stringstream   src_script;

  src_script << src_file.rdbuf();

  std::string s = src_script.str();

  return s;
}
Exemple #4
0
void attach_sfx_module(const wstring& file_path, const SfxOptions& sfx_options) {
  AttachSfxModuleProgress progress(file_path);

  {
    OpenOptions options;
    options.arc_path = file_path;
    options.detect = false;
    options.arc_types.push_back(c_7z);
    unique_ptr<Archives> archives(Archive::open(options));
    if (archives->empty())
      FAIL_MSG(Far::get_msg(MSG_ERROR_SFX_CONVERT));
    if (!archives->front()->is_pure_7z())
      FAIL_MSG(Far::get_msg(MSG_ERROR_SFX_CONVERT));
  }

  FindData file_data = File::get_find_data(file_path);
  progress.set_total(file_data.size());
  wstring dst_path = file_path + c_sfx_ext;
  try {
    create_sfx_module(dst_path, sfx_options);

    File dst_file(dst_path, FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, OPEN_EXISTING, 0);
    dst_file.set_pos(0, FILE_END);

    File src_file(file_path, FILE_READ_DATA, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN);
    Buffer<char> buf(1024 * 1024);
    while (true) {
      unsigned size_read = src_file.read(buf.data(), static_cast<unsigned>(buf.size()));
      if (size_read == 0)
        break;
      CHECK(dst_file.write(buf.data(), size_read) == size_read);
      progress.update_completed(size_read);
    }

    File::set_attr(file_path, file_data.dwFileAttributes);
    dst_file.set_time(file_data.ftCreationTime, file_data.ftLastAccessTime, file_data.ftLastWriteTime);
  }
  catch (...) {
    File::delete_file_nt(dst_path);
    throw;
  }
  File::delete_file_nt(file_path);
}
Exemple #5
0
int tibun_main(int argc, _TCHAR* argv[])
{
	if (argc >= 3)
	{
		FileEx src_file(argv[1]);
		FileEx out_file(argv[2]);
		if (src_file.Open()) {
			if (out_file.Create()) {
				return Unpack(&src_file, &out_file);
			}
			else
				_tprintf(_T("Cannot create file %s\n"), argv[2]);
		}
		else
			_tprintf(_T("Cannot open file %s\n"), argv[1]);
	}
	else
		_tprintf(_T("Usage: <*.tib> <out file>\n"));

	return -1;
}
Exemple #6
0
void Application::copyFilesRecursively(const QString &src_path, const QString &dst_path)
{
    QFileInfo src_file(src_path);

    if(!src_file.exists())
        throw Exception(Exception::getErrorMessage(ERR_FILE_DIR_NOT_ACCESSED).arg(src_path),
                        __PRETTY_FUNCTION__,__FILE__,__LINE__);

    if(src_file.isDir())
    {
        QString new_src_path, new_dst_path;
        QStringList filenames;
        QDir dst_dir(dst_path),
             src_dir(src_path);

        if(!dst_dir.exists() && !dst_dir.mkpath(dst_path))
            throw Exception(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(dst_path),
                            __PRETTY_FUNCTION__,__FILE__,__LINE__);

        filenames = src_dir.entryList({QString("*%1").arg(GlobalAttributes::CONFIGURATION_EXT)},
                                      QDir::Files | QDir::NoDotAndDotDot);

        for(QString filename : filenames)
        {
            //Avoiding the copy of ui-style.conf file
            if(!filename.contains(GlobalAttributes::UI_STYLE_CONF))
            {
                new_src_path = src_path + src_dir.separator() + filename;
                new_dst_path = dst_path + dst_dir.separator() + filename;
                copyFilesRecursively(new_src_path, new_dst_path);
            }
        }
    }
    else if(!QFile::exists(dst_path) && !QFile::copy(src_path, dst_path))
    {
        throw Exception(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(dst_path),
                        __PRETTY_FUNCTION__,__FILE__,__LINE__);
    }
}
Exemple #7
0
Command* Runtime::Debugger::ProcessCommand(const wstring &line) {
#ifdef _DEBUG
  wcout << L"input: |" << line << L"|" << endl;
#endif

  // parser input
  is_next = is_next_line = false;
  Parser parser;
  Command* command = parser.Parse(L"?" + line);
  if(command) {
    switch(command->GetCommandType()) {
    case EXE_COMMAND:
      ProcessExe(static_cast<Load*>(command));
      break;

    case SRC_COMMAND:
      ProcessSrc(static_cast<Load*>(command));
      break;

    case ARGS_COMMAND:
      ProcessArgs(static_cast<Load*>(command));
      break;

    case QUIT_COMMAND:
      ClearBreaks();
      ClearProgram();
      wcout << L"goodbye." << endl;
      exit(0);
      break;

    case LIST_COMMAND: {
      FilePostion* file_pos = static_cast<FilePostion*>(command);

      wstring file_name;
      if(file_pos->GetFileName().size() > 0) {
        file_name = file_pos->GetFileName();
      }
      else {
        file_name = cur_file_name;
      }

      int line_num;
      if(file_pos->GetLineNumber() > 0) {
        line_num = file_pos->GetLineNumber();
      }
      else {
        line_num = cur_line_num;
      }

      const wstring &path = base_path + file_name;
      if(FileExists(path) && line_num > 0) {
        SourceFile src_file(path, cur_line_num);
        if(!src_file.Print(line_num)) {
          wcout << L"invalid line number." << endl;
          is_error = true;
        }
      }
      else {
        wcout << L"source file or line number doesn't exist, ensure the program is running." << endl;
        is_error = true;
      }
    }
      break;

    case BREAK_COMMAND:
      ProcessBreak(static_cast<FilePostion*>(command));
      break;

    case BREAKS_COMMAND:
      ProcessBreaks();
      break;

    case PRINT_COMMAND:
      ProcessPrint(static_cast<Print*>(command));
      break;

    case RUN_COMMAND:
      if(!cur_program) {
        ProcessRun();
      }
      else {
        wcout << L"instance already running." << endl;
        is_error = true;
      }
      break;

    case CLEAR_COMMAND: {
      wcout << L"  are sure you want to clear all breakpoints? [y/n] ";
      wstring line;
      getline(wcin, line);
      if(line == L"y" || line == L"yes") {
        ClearBreaks();
      }
    }
      break;

    case DELETE_COMMAND:
      ProcessDelete(static_cast<FilePostion*>(command));
      break;

    case NEXT_COMMAND:
      if(interpreter) {
        is_next = true;
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    case NEXT_LINE_COMMAND:
      if(interpreter) {
        is_next_line = true;
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    case JUMP_OUT_COMMAND:
      if(interpreter) {
        is_jmp_out = true;
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    case CONT_COMMAND:
      if(!interpreter) {
        wcout << L"program is not running." << endl;
      }
      cur_line_num = -2;
      break;

    case INFO_COMMAND:
      ProcessInfo(static_cast<Info*>(command));
      break;

    case STACK_COMMAND:
      if(interpreter) {
        wcout << L"stack:" << endl;
        StackMethod* method = cur_frame->method;
        wcerr << L"  frame: pos=" << cur_call_stack_pos << L", class=" << method->GetClass()->GetName() 
							<< L", method=" << PrintMethod(method);
        const long ip = cur_frame->ip;
        if(ip > -1) {
          StackInstr* instr = cur_frame->method->GetInstruction(ip);
          wcerr << L", file=" << method->GetClass()->GetFileName() << L":" << instr->GetLineNumber() << endl;
        }
        else {
          wcerr << endl;
        }

        long pos = cur_call_stack_pos - 1;
        do {
          StackMethod* method = cur_call_stack[pos]->method;
          wcerr << L"  frame: pos=" << pos << L", class=" << method->GetClass()->GetName() 
								<< L", method=" << PrintMethod(method);
          const long ip = cur_call_stack[pos]->ip;
          if(ip > -1) {
            StackInstr* instr = cur_call_stack[pos]->method->GetInstruction(ip);
            wcerr << L", file=" << method->GetClass()->GetFileName() << L":" << instr->GetLineNumber() << endl;
          }
          else {
            wcerr << endl;
          }
        }
        while(--pos);
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    default:
      break;
    }

    is_error = false;
    ref_mem = NULL;
    return command;
  }
  else {
    wcout << L"-- Unable to process command --" << endl;
  }

  is_error = false;
  ref_mem = NULL;
  return NULL;
}
Exemple #8
0
int main(int argc, char** argv)
{ 
      try{
      if(argc != 4)
	throw std::string("invalid use");
      std::string src_file_name = argv[1];
      std::string dest_file_name = argv[2];
      std::string gen_file_name =argv[3];
      
      
      std::list<Individu> lIndividu; 

     
      /* ------------------------------------------------- */
      /* ------ PARSING INPUT FILE ----------------------- */
      /* ------------------------------------------------- */

      /* Parsing algorithm :                               */
      /* 1) parse the first few line individu              */
      /*   warn to a single line, which was use            */
      /*   to find the end of the first generation         */
      /* 2) parse the end of the file                      */

      /* first reading to parse individu */
       std::ifstream src_file(src_file_name.c_str(), std::ios::in);
      if(!src_file)
	throw std::string("can't open file \"" + src_file_name + "\"");
      
      
      /* step 1) */
      /* insert the first generation in lIndividu */
      std::string type;
      bool firstGen = true;
      while(firstGen)
	{ 
	  src_file >> type;
	  if(type == "Individu")
	  {
	      /* Parsing Individu line */ 
	    std::string semicolon, tmp1, tmp2, tmp3;
	    std::string sNoGen, sId, sFitness, sGainFitness;
	    int noGen, id;
	    float fitness,gainFitness;
	    src_file >> semicolon >> sNoGen >> noGen >> tmp1 >> sId >> id >> tmp2 >> sFitness >> fitness >> tmp3 >> sGainFitness >> gainFitness;

	      Individu mIndividu;
	      mIndividu.id = id;
	      mIndividu.gen=noGen;
	      mIndividu.fitness = fitness;
	      mIndividu.parent1 = 0;
	      mIndividu.parent2 = 0;
	      mIndividu.origine = 0;
	      mIndividu.gain_fitness = 0;
	      mIndividu.survival=0;

	      lIndividu.push_back(mIndividu);
	  }
	  else
	    { 
	      firstGen = false;
	    }
	}