void CrashHandler::attemptCrashsave()
{
    QDir crashSave;
    crashSave.setCurrent(AppPathManager::userAppDir());

    /*
     * For case if crash happened while ... attempt to load crashed files!
     * This avoids looping crashes because backup files are causing crash too!
     */
    if(crashSave.exists("__crashsave"))
    {
        LogCriticalNC("We are detected that crash has been occouped on attempt to load or initialize backup files. Backup directory has been renamed into \"__crashsave_danger\".");
        LogCriticalNC("Please attach all files in that directory and, if possible, additional contents (custom images, sounds, musics, configs and scripts) while reporting this crash.");
        QDir    dupeDir(AppPathManager::userAppDir() + "/__crashsave_danger");

        if(dupeDir.exists())
            dupeDir.removeRecursively();

        crashSave.rename("__crashsave", "__crashsave_danger");
        return;
    }

    crashSave.mkdir("__crashsave");
    crashSave.cd("__crashsave");
    int untitledCounter = 0;
    MainWindow *mw = MainWinConnect::pMainWin;

    if(!mw) return;

    QList<QMdiSubWindow *> listOfAllSubWindows = mw->allEditWins();

    for(QMdiSubWindow *subWin : listOfAllSubWindows)
    {
        if(mw->activeChildWindow(subWin) == MainWindow::WND_Level)
        {
            LevelEdit *lvledit = mw->activeLvlEditWin(subWin);

            if(!lvledit)
                continue;

            QString fName = lvledit->currentFile();

            if(lvledit->isUntitled())
                fName = QString("Untitled_Crash") + QString::number(untitledCounter++) + QString(".lvlx");
            else
                fName = fName.section("/", -1) + QString(".lvlx");

            LevelData &lvl = lvledit->LvlData;
            lvl.metaData.crash.used = true;
            lvl.metaData.crash.untitled = lvl.meta.untitled;
            lvl.metaData.crash.modifyed = lvl.meta.modified;
            lvl.metaData.crash.strictModeSMBX64 = lvl.meta.smbx64strict;
            lvl.metaData.crash.fmtID    = lvl.meta.RecentFormat;
            lvl.metaData.crash.fmtVer   = lvl.meta.RecentFormatVersion;
            lvl.metaData.crash.filename = lvl.meta.filename;
            lvl.metaData.crash.path     = lvl.meta.path;
            lvl.metaData.crash.fullPath = lvledit->curFile;
            //Forcely save data into PGE-X format
            lvl.meta.RecentFormat = LevelData::PGEX;
            lvledit->saveFile(crashSave.absoluteFilePath(fName), false);
        }
        else if(mw->activeChildWindow(subWin) == MainWindow::WND_NpcTxt)
        {
            NpcEdit *npcedit = mw->activeNpcEditWin(subWin);

            if(!npcedit)
                continue;

            QString fName = npcedit->currentFile();

            if(npcedit->isUntitled())
                fName = QString("Untitled_Crash") + QString::number(untitledCounter++) + QString(".txt");
            else
                fName = fName.section("/", -1);

            npcedit->saveFile(crashSave.absoluteFilePath(fName), false);
        }
        else if(mw->activeChildWindow(subWin) == MainWindow::WND_World)
        {
            WorldEdit *worldedit = mw->activeWldEditWin(subWin);

            if(!worldedit)
                continue;

            QString fName = worldedit->currentFile();

            if(worldedit->isUntitled())
                fName = QString("Untitled_Crash") + QString::number(untitledCounter++) + QString(".wldx");
            else
                fName = fName.section("/", -1) + QString(".wldx");

            WorldData &wld = worldedit->WldData;
            wld.metaData.crash.used = true;
            wld.metaData.crash.untitled = wld.meta.untitled;
            wld.metaData.crash.modifyed = wld.meta.modified;
            wld.metaData.crash.strictModeSMBX64 = wld.meta.smbx64strict;
            wld.metaData.crash.fmtID    = wld.meta.RecentFormat;
            wld.metaData.crash.fmtVer   = wld.meta.RecentFormatVersion;
            wld.metaData.crash.filename = wld.meta.filename;
            wld.metaData.crash.path     = wld.meta.path;
            wld.metaData.crash.fullPath = worldedit->curFile;
            //Forcely save data into PGE-X format
            wld.meta.RecentFormat = WorldData::PGEX;
            worldedit->saveFile(crashSave.absoluteFilePath(fName), false);
        }
    }
}