bool Video::revert() { File_Ops &fo = get_File_Ops(); const String appdata_path = fo.get_appdata_path(); const String user_normal = appdata_path + "config/zenilib.xml"; const String user_backup = user_normal + ".bak"; const String local_normal = "config/zenilib.xml"; const String local_backup = local_normal + ".bak"; bool reverted = false; try { preinit_from_file(user_normal); get_Video(); reverted = true; } catch(Video_Init_Failure &) { } if(!reverted && fo.copy_file(user_backup, user_normal) && fo.delete_file(user_backup)) { std::cerr << '\'' << user_normal << "' backup restored due to initialization failure.\n"; try { Video::preinit_from_file(user_normal); get_Video(); reverted = true; } catch(Video_Init_Failure &) { } } if(!reverted && fo.copy_file(local_backup, local_normal) && fo.delete_file(local_backup)) { std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n"; try { Video::preinit_from_file(local_normal); get_Video(); reverted = true; } catch(Video_Init_Failure &) { } } if(!reverted) { std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n"; Video::set_failsafe_defaults(); get_Video(); reverted = true; } save(false); return true; }
void Video::change_resolution(const Point2i &resolution) { Window &wr = get_Window(); if(wr.get_width() == resolution.x && wr.get_height() == resolution.y) return; destroy(); try { preinit_from_file(get_File_Ops().get_appdata_path() + "config/zenilib.xml"); } catch(XML_Load_Failure &) { preinit_from_file("config/zenilib.xml"); } #ifndef ANDROID wr.alert_window_resized(resolution); #endif get(); }
Video * Video::create() { Video * video = 0; File_Ops &fo = get_File_Ops(); const String appdata_path = fo.get_appdata_path(); const String user_normal = appdata_path + "config/zenilib.xml"; const String user_backup = user_normal + ".bak"; const String local_normal = "config/zenilib.xml"; const String local_backup = local_normal + ".bak"; static bool last_resort_taken = false; #ifndef ANDROID try #endif { switch(Video::g_video_mode) { case Video::ZENI_VIDEO_ANY: #ifndef DISABLE_DX9 case Video::ZENI_VIDEO_DX9: video = new Video_DX9(); break; #endif #ifndef DISABLE_GL case Video::ZENI_VIDEO_GL: video = new Video_GL(); break; #endif default: throw Video_Init_Failure(); } } #ifndef ANDROID catch(Video_Init_Failure &) { if(fo.copy_file(user_backup, user_normal) && fo.delete_file(user_backup)) { std::cerr << '\'' << user_normal << "' backup restored due to initialization failure.\n"; Video::preinit_from_file(user_normal); get_Video(); } else if(fo.copy_file(local_backup, local_normal) && fo.delete_file(local_backup)) { std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n"; Video::preinit_from_file(local_normal); get_Video(); } else if(!last_resort_taken) { Video::set_failsafe_defaults(); last_resort_taken = true; get_Video(); } else throw; } #endif last_resort_taken = false; return video; }
void Video::save(const bool &backup) { File_Ops &fo = get_File_Ops(); // Initialize paths const String appdata_path = fo.get_appdata_path(); const String user_normal = appdata_path + "config/zenilib.xml"; const String user_backup = user_normal + ".bak"; const String local_normal = "config/zenilib.xml"; const String local_backup = local_normal + ".bak"; // Create file XML_Document file; if(!file.try_load(user_normal)) file.load(local_normal); XML_Element zenilib = file["Zenilib"]; XML_Element textures = zenilib["Textures"]; XML_Element video = zenilib["Video"]; textures["Anisotropy"].set_int(Textures::get_anisotropic_filtering()); textures["Bilinear_Filtering"].set_bool(Textures::get_bilinear_filtering()); textures["Mipmapping"].set_bool(Textures::get_mipmapping()); video["API"].set_string( #if !defined(DISABLE_DX9) && !defined(DISABLE_GL) g_video_mode == Video::ZENI_VIDEO_DX9 ? "DX9" : "OpenGL"); #elif !defined(DISABLE_DX9) "DX9"); #elif !defined(DISABLE_GL) "OpenGL"); #else "Disabled"); #endif video["Full_Screen"].set_bool(Window::is_full_screen()); video["Multisampling"].set_int(g_multisampling); video["Resolution"]["Width"].set_int(Window::get_width()); video["Resolution"]["Height"].set_int(Window::get_height()); video["Vertical_Sync"].set_bool(g_vertical_sync); // User-specific backup and save bool user_save = false; if(fo.create_directory(appdata_path) && fo.create_directory(appdata_path + "config/")) { if(backup) fo.copy_file(user_normal, user_backup); user_save = file.try_save(user_normal); } // Local backup and save if(backup) { if(user_save) fo.copy_file(user_normal, local_backup); else fo.copy_file(local_normal, local_backup); } file.try_save(local_normal); }
Window * Window::create() { Window * window = 0; #ifndef ANDROID File_Ops &fo = get_File_Ops(); const String appdata_path = fo.get_appdata_path(); const String user_normal = appdata_path + "config/zenilib.xml"; const String user_backup = user_normal + ".bak"; const String local_normal = "config/zenilib.xml"; const String local_backup = local_normal + ".bak"; static bool last_resort_taken = false; #endif #ifndef ANDROID try { switch(Video::get_video_mode()) { case Video::ZENI_VIDEO_ANY: #ifndef DISABLE_GL_SHADER case Video::ZENI_VIDEO_GL_SHADER: Window::set_opengl_flag(true); break; #endif #ifndef DISABLE_DX9 case Video::ZENI_VIDEO_DX9: Window::set_opengl_flag(false); break; #endif #ifndef DISABLE_GL_FIXED case Video::ZENI_VIDEO_GL_FIXED: Window::set_opengl_flag(true); break; #endif default: throw Window_Init_Failure(); } #endif window = new Window; #ifndef ANDROID } catch(Window_Init_Failure &) { if(fo.copy_file(user_backup, user_normal) && fo.delete_file(user_backup)) { std::cerr << '\'' << user_normal << "' backup restored due to initialization failure.\n"; Video::preinit_from_file(user_normal); get_Window(); } else if(fo.copy_file(local_backup, local_normal) && fo.delete_file(local_backup)) { std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n"; Video::preinit_from_file(local_normal); get_Window(); } else if(!last_resort_taken) { Window::set_failsafe_defaults(); last_resort_taken = true; get_Window(); } else throw; } last_resort_taken = false; #endif return window; }