Skip to content

Commit

Permalink
Move presets to profile directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jecassis committed Feb 16, 2024
1 parent 9a23573 commit 02ab21d
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 229 deletions.
2 changes: 1 addition & 1 deletion foo_vis_milk2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class milk2_config

private:
uint32_t m_sentinel = ('M' << 24 | 'I' << 16 | 'L' << 8 | 'K');
uint32_t m_version = 1u;
uint32_t m_version = 2u;

static void initialize_paths();
void update_paths();
Expand Down
107 changes: 19 additions & 88 deletions foo_vis_milk2/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ static constexpr int default_nMinFeatureLevel = D3D_FEATURE_LEVEL_9_1;
static constexpr UINT default_max_fps_fs = 30;
static constexpr bool default_allow_page_tearing_fs = false;

static WCHAR default_szComponentDirPath[MAX_PATH];
static WCHAR default_szPluginsDirPath[MAX_PATH];
static WCHAR default_szConfigIniFile[MAX_PATH];
static WCHAR default_szMilkdrop2Path[MAX_PATH];
static WCHAR default_szPresetDir[MAX_PATH];
static CHAR default_szPresetDirA[MAX_PATH];
static WCHAR default_szMsgIniFile[MAX_PATH];
static WCHAR default_szImgIniFile[MAX_PATH];

Expand Down Expand Up @@ -1067,21 +1067,25 @@ void milk2_config::reset()

void milk2_config::initialize_paths()
{
std::string base_path = core_api::get_my_full_path();
std::string::size_type t = base_path.rfind('\\');
std::string component_path = core_api::get_my_full_path();
std::string::size_type t = component_path.rfind('\\');
if (t != std::string::npos)
base_path.erase(t + 1);

swprintf_s(default_szPluginsDirPath, L"%hs", const_cast<char*>(base_path.c_str()));
swprintf_s(default_szConfigIniFile, L"%hs%ls", const_cast<char*>(base_path.c_str()), INIFILE);
component_path.erase(t + 1);
std::string profile_path = core_api::get_profile_path();
assert(strncmp(profile_path.substr(0, 7).c_str(), "file://", 7) == 0);
profile_path = profile_path.substr(7);
profile_path.append("\\");

swprintf_s(default_szComponentDirPath, L"%hs", const_cast<char*>(component_path.c_str()));
swprintf_s(default_szPluginsDirPath, L"%hs", const_cast<char*>(profile_path.c_str()));
swprintf_s(default_szMilkdrop2Path, L"%ls%ls", default_szPluginsDirPath, SUBDIR);
swprintf_s(default_szConfigIniFile, L"%ls%ls", default_szMilkdrop2Path, INIFILE);
swprintf_s(default_szPresetDir, L"%lspresets\\", default_szMilkdrop2Path);
wcstombs_s(nullptr, default_szPresetDirA, default_szPresetDir, MAX_PATH);
wchar_t szConfigDir[MAX_PATH] = {0};
wcscpy_s(szConfigDir, default_szConfigIniFile);
wchar_t* p = wcsrchr(szConfigDir, L'\\');
if (p)
*(p + 1) = 0;
*(p + 1) = L'\0';
swprintf_s(default_szMsgIniFile, L"%ls%ls", szConfigDir, MSG_INIFILE);
swprintf_s(default_szImgIniFile, L"%ls%ls", szConfigDir, IMG_INIFILE);
}
Expand All @@ -1090,16 +1094,17 @@ void milk2_config::update_paths()
{
if (cfg_szPresetDir.get().empty())
{
CHAR szPresetDirA[MAX_PATH];
wcscpy_s(settings.m_szPresetDir, default_szPresetDir);
cfg_szPresetDir.set(default_szPresetDirA);
strcpy_s(settings.m_szPresetDirA, default_szPresetDirA);
wcstombs_s(nullptr, szPresetDirA, default_szPresetDir, MAX_PATH);
cfg_szPresetDir.set(szPresetDirA);
}
else
{
size_t convertedChars;
mbstowcs_s(&convertedChars, settings.m_szPresetDir, cfg_szPresetDir.get().c_str(), _TRUNCATE);
strcpy_s(settings.m_szPresetDirA, cfg_szPresetDir.get().c_str());
mbstowcs_s(&convertedChars, settings.m_szPresetDir, cfg_szPresetDir.get().c_str(), MAX_PATH);
}
wcscpy_s(settings.m_szComponentDirPath, default_szComponentDirPath);
wcscpy_s(settings.m_szPluginsDirPath, default_szPluginsDirPath);
wcscpy_s(settings.m_szConfigIniFile, default_szConfigIniFile);
wcscpy_s(settings.m_szMilkdrop2Path, default_szMilkdrop2Path);
Expand All @@ -1117,94 +1122,28 @@ void milk2_config::parse(ui_element_config_parser& parser)
parser >> version;
switch (version)
{
case 1:
//parser >> m_multisample_fs;
//parser >> m_multisample_w;

//parser >> m_start_fullscreen;
//parser >> m_max_fps_fs;
//parser >> m_show_press_f1_msg;
//parser >> m_allow_page_tearing_fs;
//parser >> m_minimize_winamp;
//parser >> m_dualhead_horz;
//parser >> m_dualhead_vert;
//parser >> m_save_cpu;
//parser >> m_skin;
//parser >> m_fix_slow_text;

//parser >> m_disp_mode_fs;

//parser >> settings.m_bEnableRating;
//parser >> settings.m_bHardCutsDisabled;
//parser >> settings.g_bDebugOutput;
//parser >> settings.m_bShowSongInfo;
//parser >> settings.m_bShowPressF1ForHelp;
//parser >> settings.m_bShowMenuToolTips;
//parser >> settings.m_bSongTitleAnims;

case 2:
parser >> settings.m_bShowFPS;
parser >> settings.m_bShowRating;
parser >> settings.m_bShowPresetInfo;
//parser >> settings.m_bShowDebugInfo;
parser >> settings.m_bShowSongTitle;
parser >> settings.m_bShowSongTime;
parser >> settings.m_bShowSongLen;
parser >> settings.m_bShowShaderHelp;

//parser >> settings.m_bFixPinkBug;
//parser >> settings.m_n16BitGamma;
//parser >> settings.m_bAutoGamma;
//parser >> settings.m_bAlways3D;
//parser >> settings.m_fStereoSep;
//parser >> settings.m_bFixSlowText;
//parser >> settings.m_bAlwaysOnTop;
//parser >> settings.m_bWarningsDisabled;
//parser >> settings.m_bWarningsDisabled2;
//parser >> settings.m_bAnisotropicFiltering;
//parser >> settings.m_bPresetLockOnAtStartup;
//parser >> settings.m_bPreventScollLockHandling;

//parser >> settings.m_nCanvasStretch;
//parser >> settings.m_nTexSizeX;
parser >> settings.m_nTexSizeY;
parser >> settings.m_bTexSizeWasAutoPow2;
parser >> settings.m_bTexSizeWasAutoExact;
//parser >> settings.m_nTexBitsPerCh;
//parser >> settings.m_nGridX;
parser >> settings.m_nGridY;
//parser >> settings.m_nMaxPSVersion;
//parser >> settings.m_nMaxImages;
//parser >> settings.m_nMaxBytes;

//parser >> settings.m_fBlendTimeUser;
//parser >> settings.m_fBlendTimeAuto;
//parser >> settings.m_fTimeBetweenPresets;
//parser >> settings.m_fTimeBetweenPresetsRand;
//parser >> settings.m_fHardCutLoudnessThresh;
//parser >> settings.m_fHardCutHalflife;
//parser >> settings.m_fSongTitleAnimDuration;
//parser >> settings.m_fTimeBetweenRandomSongTitles;
//parser >> settings.m_fTimeBetweenRandomCustomMsgs;

parser >> settings.m_bPresetLockedByCode;
//parser >> settings.m_bPresetLockedByUser;
//parser >> settings.m_bMilkdropScrollLockState;
//parser >> settings.m_nFpsLimit;

parser >> settings.m_bEnableDownmix;
parser >> settings.m_bEnableHDR;
parser >> settings.m_nBackBufferFormat;
parser >> settings.m_nDepthBufferFormat;
parser >> settings.m_nBackBufferCount;
parser >> settings.m_nMinFeatureLevel;

parser >> settings.m_szPluginsDirPath;
parser >> settings.m_szConfigIniFile;
parser >> settings.m_szMilkdrop2Path;
parser >> settings.m_szPresetDir;
parser >> settings.m_szPresetDirA;
parser >> settings.m_szMsgIniFile;
parser >> settings.m_szImgIniFile;
break;
default:
FB2K_console_formatter() << core_api::get_my_file_name() << ": Unknown configuration format version: " << version;
Expand Down Expand Up @@ -1301,12 +1240,4 @@ void milk2_config::build(ui_element_config_builder& builder)
builder << settings.m_nDepthBufferFormat;
builder << settings.m_nBackBufferCount;
builder << settings.m_nMinFeatureLevel;

builder << settings.m_szPluginsDirPath;
builder << settings.m_szConfigIniFile;
builder << settings.m_szMilkdrop2Path;
builder << settings.m_szPresetDir;
builder << settings.m_szPresetDirA;
builder << settings.m_szMsgIniFile;
builder << settings.m_szImgIniFile;
}
5 changes: 2 additions & 3 deletions foo_vis_milk2/ui_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,8 @@ LRESULT milk2_ui_element::OnMilk2Message(UINT uMsg, WPARAM wParam, LPARAM lParam
else if (lParam == IPC_GETINIDIRECTORYW)
{
m_szBuffer = s_config.settings.m_szConfigIniFile;
size_t p = m_szBuffer.find_last_of(L"\\");
m_szBuffer = m_szBuffer.substr(0, p + 1);
return reinterpret_cast<LRESULT>(m_szBuffer.c_str());
}

Expand Down Expand Up @@ -1503,9 +1505,6 @@ bool milk2_ui_element::Initialize(HWND window, int width, int height)
{
if (!s_milk2)
{
swprintf_s(g_plugin.m_szPluginsDirPath, L"%hs", const_cast<char*>(m_pwd.c_str()));
swprintf_s(g_plugin.m_szConfigIniFile, L"%hs%ls", const_cast<char*>(m_pwd.c_str()), INIFILE);

if (FALSE == g_plugin.PluginPreInitialize(window, core_api::get_my_instance()))
return false;
if (!g_plugin.PanelSettings(&s_config.settings))
Expand Down
2 changes: 1 addition & 1 deletion foo_vis_milk2/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define APPLICATION_VERSION_MAJOR 0
#define APPLICATION_VERSION_MINOR 0
#define APPLICATION_VERSION_BUILD 229
#define APPLICATION_VERSION_BUILD 230
#define APPLICATION_VERSION_REVISION -3 // -3: alpha, -2: beta, -1: release candidate, >= 0 && < 32768: not development version

#define LIBRARY_VERSION_MAJOR 2 // INT_VERSION / 100
Expand Down
Loading

0 comments on commit 02ab21d

Please sign in to comment.