Skip to content

Commit

Permalink
added inifile support though filthy static class thingy.
Browse files Browse the repository at this point in the history
  • Loading branch information
eteeselink authored and kusma committed Mar 19, 2010
1 parent cd0e127 commit da96ca4
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 18 deletions.
6 changes: 5 additions & 1 deletion editor/editor.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib comctl32.lib "
AdditionalDependencies="ws2_32.lib comctl32.lib comsupp.lib comsuppwd.lib"
LinkIncremental="2"
GenerateManifest="false"
GenerateDebugInformation="true"
Expand Down Expand Up @@ -185,6 +185,10 @@
RelativePath="..\sync\data.cpp"
>
</File>
<File
RelativePath=".\inifile.cpp"
>
</File>
<File
RelativePath="..\sync\network.cpp"
>
Expand Down
4 changes: 4 additions & 0 deletions editor/inifile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "inifile.h"

std::string IniFile::filename;
std::string IniFile::section;
62 changes: 62 additions & 0 deletions editor/inifile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include <string>
#include <windows.h>

class IniFile
{
protected:
static std::string filename;
static std::string section;
public:

static std::string getFullPath(std::string filename)
{
char fullpath[100];
char* dummy;
GetFullPathName(filename.c_str(), 100, fullpath, &dummy);
return std::string(fullpath);
}
static void load(std::string filename)
{
IniFile::filename = getFullPath(filename);
}
static void load(std::string filename, std::string section)
{
load(filename);
setSection(section);
}
static void setSection(std::string section)
{
IniFile::section = section;
}
static bool check()
{
char buf[10];
return (GetPrivateProfileSectionNames( buf, 10, filename.c_str() )) ? true : false;
}
static int get(std::string filename, std::string section, std::string key, int defaultValue=INT_MAX)
{
return GetPrivateProfileInt(section.c_str(), key.c_str(), defaultValue, filename.c_str());
}
static int get(std::string section, std::string key, int defaultValue=INT_MAX)
{
return get(filename, section, key, defaultValue);
}
static int get(std::string key, int defaultValue=INT_MAX)
{
return get(filename, section, key, defaultValue);
}
static void read(int &var, std::string filename, std::string section, std::string key)
{
var = get(filename, section, key, var);
}
static void read(int &var, std::string section, std::string key)
{
var = get(filename, section, key, var);
}
static void read(int &var, std::string key)
{
var = get(filename, section, key, var);
}
};
3 changes: 3 additions & 0 deletions editor/rocket.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[GUI]
fontHeight = 14
fontWidth = 5
1 change: 1 addition & 0 deletions editor/syncdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "../sync/network.h"
#include "../sync/data.h"
#include "inifile.h"
#include <stack>
#include <list>

Expand Down
14 changes: 12 additions & 2 deletions editor/trackview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ static const TCHAR *trackViewWindowClassName = _T("TrackView");
static const int topMarginHeight = 20;
static const int leftMarginWidth = 60;

static const int fontHeight = 16;
static const int fontWidth = 6;
static int fontHeight = 16;
static int fontWidth = 6;

static const int trackWidth = fontWidth * 16;
static DWORD darken(DWORD col, float amt)
Expand All @@ -21,6 +21,16 @@ static DWORD darken(DWORD col, float amt)

TrackView::TrackView()
{
IniFile::load("rocket.ini", "GUI");

if(IniFile::check())
{
//read directly into variables, using their current values
//as defaults in case the ini file or the keys are not found.
IniFile::read(fontHeight, "fontHeight");
IniFile::read(fontWidth, "fontWidth");
}

scrollPosX = 0;
scrollPosY = 0;
windowWidth = -1;
Expand Down
17 changes: 2 additions & 15 deletions synctracker2.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "editor", "editor\editor.vcproj", "{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_bass", "example_bass\example_bass.vcproj", "{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}"
ProjectSection(ProjectDependencies) = postProject
{5866042C-7FCB-4DB1-BAAD-44DF6567511F} = {5866042C-7FCB-4DB1-BAAD-44DF6567511F}
EndProjectSection
# Visual C++ Express 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sync_editor", "editor\editor.vcproj", "{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sync_player", "sync_player.vcproj", "{5866042C-7FCB-4DB1-BAAD-44DF6567511F}"
EndProject
Expand All @@ -26,14 +21,6 @@ Global
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release Client|Win32.Build.0 = Release|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release|Win32.ActiveCfg = Release|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release|Win32.Build.0 = Release|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug Client|Win32.ActiveCfg = Debug|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug Client|Win32.Build.0 = Debug|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug|Win32.ActiveCfg = Debug|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug|Win32.Build.0 = Debug|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release Client|Win32.ActiveCfg = Release|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release Client|Win32.Build.0 = Release|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release|Win32.ActiveCfg = Release|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release|Win32.Build.0 = Release|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug Client|Win32.ActiveCfg = Debug Client|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug Client|Win32.Build.0 = Debug Client|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug|Win32.ActiveCfg = Debug|Win32
Expand Down

0 comments on commit da96ca4

Please sign in to comment.