void timeManage::save_shutdown(){
    extern ci::fs::path getDocumentPath();
    Path = getDocumentPath();
    JsonTree ex_json;
    
    if(ci::fs::is_regular_file(Path / "Save.json")){
      
      JsonTree ex_json = JsonTree(loadFile(Path / "Save.json"));
      
      ex_json = ci::JsonTree::makeObject(("Time"));
      ex_json.addChild(JsonTree("year",time_object->tm_year));
      ex_json.addChild(JsonTree("month",time_object->tm_mon));
      ex_json.addChild(JsonTree("day",time_object->tm_mday));
      ex_json.addChild(JsonTree("hour",time_object->tm_hour));
      ex_json.addChild(JsonTree("minute",time_object->tm_min));
      ex_json.addChild(JsonTree("second",time_object->tm_sec));
    
      ex_json.write(Path / "Save.json",JsonTree::WriteOptions().createDocument(true));
        
    }
    else{
      ex_json = ci::JsonTree::makeObject(("Time"));
      ex_json.addChild(JsonTree("year",time_object->tm_year));
      ex_json.addChild(JsonTree("month",time_object->tm_mon));
      ex_json.addChild(JsonTree("day",time_object->tm_mday));
      ex_json.addChild(JsonTree("hour",time_object->tm_hour));
      ex_json.addChild(JsonTree("minute",time_object->tm_min));
      ex_json.addChild(JsonTree("second",time_object->tm_sec));

      ex_json.write(Path / "Save.json",JsonTree::WriteOptions().createDocument(true));
    }
}
/// Function name  : findDocumentIndexByPath
// Description     : Determines the index of the specified document
// 
// HWND          hTabCtrl     : [in]  Documents control
// CONST TCHAR*  szFullPath   : [in]  Full path of the desired document
// INT&          iOutput      : [out] Zero-based index if found, otherwise -1
// 
// Return Value   : TRUE if found, otherwise FALSE
// 
BOOL   findDocumentIndexByPath(HWND  hTabCtrl, CONST TCHAR*  szFullPath, INT&  iOutput)
{
   DOCUMENTS_DATA* pWindowData;    // Window data
   LIST_ITERATOR*  pIterator;      // List iterator
   DOCUMENT*       pDocument;      // List iterator

   
   // Prepare
   pWindowData = getDocumentsControlData(hTabCtrl);
   iOutput     = -1;
   
   /// Iterate through document list
   for (pIterator = createListIterator(pWindowData->pDocumentList); getCurrentItem(pIterator, (LPARAM&)pDocument); moveNextItem(pIterator))
   {
      // [CHECK] Compare paths
      if (utilCompareStringVariables(getDocumentPath(pDocument), szFullPath))
      {
         /// [FOUND] Set result and abort
         iOutput = pIterator->iIndex;
         break;
      }
   }

   // Cleanup and return TRUE if found
   deleteListIterator(pIterator);
   return (iOutput != -1);
}
void timeManage::check_timelag(){
    extern ci::fs::path getDocumentPath();
    Path = getDocumentPath();
    
  console() <<Path / "Save.json"<< std::endl;
    if(ci::fs::is_regular_file(Path / "Save.json")) {
    
    JsonTree ex_json(loadFile(Path / "Save.json"));
        console() <<Path / "Save.json"<< std::endl;
      int year,month,day,hour,minute,sec;
      year   = ex_json["Time"]["year"].getValue<float>();
      month  = ex_json["Time"]["month"].getValue<float>();
      day    = ex_json["Time"]["day"].getValue<int>();
      hour   = ex_json["Time"]["hour"].getValue<int>();
      minute = ex_json["Time"]["minute"].getValue<int>();
      sec    = ex_json["Time"]["second"].getValue<int>();
    
    
      long past_time =
      (year * 315360000)     +
      ((month +1) * 2592000) +
      (day * 86400) +
      (hour * 3600) +
      (minute * 60) +
      (sec);
   
      long current_time =
      (time_object->tm_year       * 315360000) +
      ((time_object->tm_mon + 1)  * 2592000) +
      (time_object->tm_mday * 86400) +
      (time_object->tm_hour * 3600) +
      (time_object->tm_min * 60)  +
      (time_object->tm_sec);
    
      long time_lag = current_time - past_time;
        console() << "time_lag :" << time_lag /60 << std::endl;
      if(time_lag >= 60 * 60 * 60 * 3){
          gaptime = 60*(60 * 60 * 60 * 3);
      }
      else{
          gaptime = static_cast<int>(time_lag) * 60;
      }
    }
    
    
   
}
bool timeManage::is_firstplay(){
    
    extern ci::fs::path getDocumentPath();
    Path = getDocumentPath();
    
    //セーブデータがあるかを判定.
    //続きからならロード、はじめからならセーブデータを書き込み.
    if(ci::fs::is_regular_file(Path / "First.json")) {
       
        check_timelag();
        return true;
    }
    else{
        json_load.write(Path / "First.json",JsonTree::WriteOptions().createDocument(true));
        return false;
    }
}
void NSRPopplerDocument::createInternalDoc(QString passwd)
{
	SplashColor	bgColor;
	GooString	*fileName;
	GooString	*passwdStr;

	if (_doc != NULL)
		return;

	bgColor[0] = 255;
	bgColor[1] = 255;
	bgColor[2] = 255;
	_dev = new SplashOutputDev(splashModeRGB8, 4, gFalse, bgColor);

	fileName = new GooString (getDocumentPath().toUtf8().data());

	if (!passwd.isEmpty())
		passwdStr = new GooString (passwd.toUtf8().data());
	else
		passwdStr = NULL;

	_doc = new PDFDoc (fileName, passwdStr);

	if (!_doc->isOk()) {
		if (_doc->getErrorCode() == errEncrypted)
			setLastError (NSR_DOCUMENT_ERROR_PASSWD);
		else
			setLastError (NSR_DOCUMENT_ERROR_UNKNOWN);

		delete _doc;
		_doc = NULL;

#ifdef Q_OS_SYMBIAN
		_iBitmap = NULL;
#endif
		return;
	}

#ifdef Q_OS_SYMBIAN
	_iBitmap = new CFbsBitmap ();
#endif
	_catalog = _doc->getCatalog();
	_page = _catalog->getPage(1);
	_dev->startDoc(_doc->getXRef());
}
/// Function name  : onDependenciesPage_PerformSearch
// Description     : Initiates a script-call search operation
// 
// PROPERTIES_DATA*  pSheetData   : [in] Properties sheet dialog data
// HWND              hPage        : [in] Window handle of the dependencies page
// 
VOID  onDependenciesPage_PerformSearch(SCRIPT_DOCUMENT*  pDocument, HWND  hPage)
{
   SCRIPT_CONTENT     xContent;
   TCHAR*             szFolder;

   // Get script folder
   szFolder = utilDuplicateFolderPath(getDocumentPath(pDocument));

   // [QUESTION] "Would you like to search '%s' for all scripts that depend upon '%s'?"
   if (displayMessageDialogf(NULL, IDS_GENERAL_CONFIRM_DEPENDENCY_SEARCH, MDF_YESNO WITH MDF_QUESTION, szFolder, identifyScriptName(pDocument->pScriptFile)) == IDYES)
   {
      // [VERBOSE]
      CONSOLE_COMMAND();
      
      /// Launch search thread
      xContent.asScript = identifyScriptName(pDocument->pScriptFile);
      launchOperation(getMainWindowData(), createScriptOperationData(CT_SCRIPT, szFolder, xContent));
   }

   // Cleanup
   utilDeleteString(szFolder);
}
  RootController(ci::JsonTree& params,
                 ci::TimelineRef timeline,
                 Event<std::vector<Touch> >& touch_event) noexcept :
    params_(params),
    timeline_(timeline),
    ui_camera_(createCamera(params["ui_view.camera"])),
    fov_(ui_camera_.getFov()),
    near_z_(ui_camera_.getNearClip()),
    far_z_(ui_camera_.getFarClip()),
    autolayout_(ui_camera_),
    touch_event_(touch_event),
    view_creator_(params, timeline, ui_camera_, autolayout_, event_, touch_event),
    sound_(params["sounds"]),
    background_(Json::getColor<float>(params["app.background"])),
    records_(params["version"].getValue<float>())
  {
    DOUT << "RootController()" << std::endl;
    
    event_.connect("begin-progress",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<ProgressController>(params_, timeline_, event_,
                                                       view_creator_.create("ui_progress.json"));
                   });
    
    event_.connect("begin-gameover",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<GameoverController>(params_, timeline_, event_,
                                                       param,
                                                       view_creator_.create("ui_gameover.json"));
                   });

    event_.connect("begin-stageclear",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<StageclearController>(params_, timeline_, event_, param,
                                                         view_creator_.create("ui_stageclear.json"));
                   });

    event_.connect("begin-pause",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<PauseController>(params_, timeline_, event_,
                                                    view_creator_.create("ui_pause.json"));
                   });

    event_.connect("begin-records",
                   [this](const Connection&, EventParam& param) noexcept {
                     EventParam records = {
                       { "total_play",  records_.getTotalPlayNum() },
                       { "total_time",  records_.getTotalPlayTime() },
                       { "high_score",  records_.getHighScore() },
                       { "total_item",  records_.getTotalItemNum() },
                       { "stage_ranks", records_.stageRanks() },
                     };
                     
                     addController<RecordsController>(params_, timeline_, event_, records,
                                                      view_creator_.create("ui_records.json"));
                   });

    event_.connect("begin-credits",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<CreditsController>(params_, timeline_, event_,
                                                      view_creator_.create("ui_credits.json"));
                   });

    event_.connect("begin-title",
                   [this](const Connection&, EventParam& param) noexcept {
                     startTitle(param);
                   });

    event_.connect("begin-settings",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<SettingsController>(params_, timeline_, event_, records_,
                                                       view_creator_.create("ui_settings.json"));
                   });

    event_.connect("begin-regulat-stageclear",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<AllStageClearController>(params_["regular_stageclear"], timeline_, event_,
                                                            param,
                                                            view_creator_.create("ui_regularstageclear.json"));
                   });

    event_.connect("begin-all-stageclear",
                   [this](const Connection&, EventParam& param) noexcept {
                     addController<AllStageClearController>(params_["all_stageclear"], timeline_, event_,
                                                            param,
                                                            view_creator_.create("ui_allstageclear.json"));
                   });

    // GameOver時に色々チェック
    event_.connect("check-after-gameover",
                   [this](const Connection&, EventParam& param) noexcept {
                     DOUT << "check-after-gameover" << std::endl;
                     Rating::popup([this]() {
                         AppSupport::pauseDraw(true);
                       },
                       [this]() {
                         AppSupport::pauseDraw(false);
                       });
                     Achievment::atGameOver(records_);
                   });

    // サウンド再生
    event_.connect("sound-play",
                   [this](const Connection&, EventParam& param) noexcept {
                     auto& name = boost::any_cast<const std::string&>(param.at("sound"));
                     player_.play(name);
                     // DOUT << "sound:" << name << std::endl;
                   });

    
    event_.connect("se-silent",
                   [this](const Connection&, EventParam& param) noexcept {
                     sound_.setBufferSilent(boost::any_cast<bool>(param["silent"]));
                   });

    event_.connect("bgm-silent",
                   [this](const Connection&, EventParam& param) noexcept {
                     sound_.setFileSilent(boost::any_cast<bool>(param["silent"]));
                   });

    
#ifdef DEBUG
    event_.connect("force-regular-completed",
                   [this](const Connection&, EventParam& param) noexcept {
                     records_.forceRegularStageComplated();
                   });

    event_.connect("cancel-regular-completed",
                   [this](const Connection&, EventParam& param) noexcept {
                     records_.cancelRegularStageComplated();
                   });

    event_.connect("clear-records",
                   [this](const Connection&, EventParam& param) noexcept {
                     records_ = Records(params_["version"].getValue<float>());
                   });

    event_.connect("do-snapshot",
                   [this](const Connection&, EventParam& param) noexcept {
                     auto surface = ci::app::copyWindowSurface();
                     auto full_path = getDocumentPath() / std::string("snapshot" + createUniquePath() + ".png");
                     ci::writeImage(full_path, surface);
                   });
    
    event_.connect("reset-records",
                   [this](const Connection&, EventParam& param) noexcept {
                     records_ = Records(params_["version"].getValue<float>());
                   });
    
    event_.connect("reset-achievement",
                   [this](const Connection&, EventParam& param) noexcept {
                     DOUT << "reset-achievement" << std::endl;
                     GameCenter::resetAchievement();
                   });
#endif

    records_.load(params["game.records"].getValue<std::string>());
    
    sound_.setBufferSilent(!records_.isSeOn());
    sound_.setFileSilent(!records_.isBgmOn());
      
    addController<FieldController>(params, touch_event_, event_, records_);

    addController<IntroController>(params_, timeline_, event_,
                                   records_.getTotalPlayNum(),
                                   view_creator_.create("ui_intro.json"));

    // 自動PAUSE
    // getSignalDidEnterBackground(Backgroundになった直後)
    // getSignalWillResignActive(アクティブでなくなる直前)
    resign_active_ = ci::app::App::get()->getSignalWillResignActive().connect([this]() noexcept {
        DOUT << "SignalWillResignActive" << std::endl;
        EventParam params = {
          { "force", true }
        };
        event_.signal("pause-agree", params);
        
        GameCenter::writeCachedAchievement();
      });
  }