profile.c
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:21k
源码类别:

VC书籍

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "globals.h"
  3. #include "CPI_Playlist.h"
  4. #include "CPI_PlaylistItem.h"
  5. ////////////////////////////////////////////////////////////
  6. //
  7. //
  8. //
  9. void    playlist_write_default(void)
  10. {
  11.     char    exepath[MAX_PATH];
  12.     main_get_program_path(GetModuleHandle(NULL), exepath, MAX_PATH);
  13.     strcat(exepath, "default.m3u");
  14.     CPL_ExportPlaylist(globals.m_hPlaylist, exepath);
  15. }
  16. //
  17. //
  18. //
  19. void    options_read(void)
  20. {
  21.     char    pathbuf[MAX_PATH];
  22.     int     teller;
  23.     int     widths[] = {   20,   200,  200,  200,  50,   50,   70,    100,  100,   100, 50};
  24.     int     visibles[] = { TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE };
  25.     int iColIDX;
  26.     main_get_program_path(NULL, pathbuf, MAX_PATH);
  27.     strcat(pathbuf, "coolplayer.ini");
  28.     for(iColIDX = PLAYLIST_first; iColIDX <= PLAYLIST_last; iColIDX++)
  29.     {
  30.         char keyname[100];
  31.         sprintf(keyname, "PlaylistCol%d", iColIDX);
  32.         options.playlist_column_widths[iColIDX] = GetPrivateProfileInt("WindowPos", keyname, widths[iColIDX], pathbuf);
  33.         sprintf(keyname, "PlaylistSeq%d", iColIDX);
  34.         options.playlist_column_seq[iColIDX] = GetPrivateProfileInt("WindowPos", keyname, iColIDX, pathbuf);
  35.         sprintf(keyname, "PlaylistVis%d", iColIDX);
  36.         options.playlist_column_visible[iColIDX] = GetPrivateProfileInt("WindowPos", keyname, visibles[iColIDX], pathbuf) ? TRUE : FALSE;
  37.     }
  38.     options.main_window_pos.x = GetPrivateProfileInt("WindowPos", // address of section name
  39.                                 "WindowX", // address of key name
  40.                                 100, // return value if key name is not found
  41.                                 pathbuf); // address of initialization filename
  42.     if (options.main_window_pos.x < -10)
  43.         options.main_window_pos.x = 100;
  44.     options.main_window_pos.y = GetPrivateProfileInt("WindowPos", // address of section name
  45.                                 "WindowY", // address of key name
  46.                                 100, // return value if key name is not found
  47.                                 pathbuf); // address of initialization filename
  48.     if (options.main_window_pos.y < -10)
  49.         options.main_window_pos.y = 100;
  50.     options.playlist_window_pos.left = GetPrivateProfileInt("WindowPos", // address of section name
  51.                                        "PlaylistX", // address of key name
  52.                                        100, // return value if key name is not found
  53.                                        pathbuf); // address of initialization filename
  54.     if (options.playlist_window_pos.left < -10)
  55.         options.playlist_window_pos.left = 100;
  56.     options.playlist_window_pos.top = GetPrivateProfileInt("WindowPos", // address of section name
  57.                                       "PlaylistY", // address of key name
  58.                                       100, // return value if key name is not found
  59.                                       pathbuf); // address of initialization filename
  60.     if (options.playlist_window_pos.top < -10)
  61.         options.playlist_window_pos.top = 100;
  62.     options.playlist_window_pos.right = GetPrivateProfileInt("WindowPos", // address of section name
  63.                                         "PlaylistW", // address of key name
  64.                                         300, // return value if key name is not found
  65.                                         pathbuf) + options.playlist_window_pos.left; // address of initialization filename
  66.     options.playlist_window_pos.bottom = GetPrivateProfileInt("WindowPos", // address of section name
  67.                                          "PlaylistH", // address of key name
  68.                                          400, // return value if key name is not found
  69.                                          pathbuf) + options.playlist_window_pos.top; // address of initialization filename
  70.     GetPrivateProfileString("LastDirectory", // points to section name
  71.                             "Directory", // points to key name
  72.                             "", // points to default string
  73.                             options.last_used_directory, // points to destination buffer
  74.                             MAX_PATH, // size of destination buffer
  75.                             pathbuf); // points to initialization filename
  76.     options.repeat_playlist =
  77.         GetPrivateProfileInt("Misc", "Repeat", 0, pathbuf);
  78.     options.shuffle_play =
  79.         GetPrivateProfileInt("Misc", "Shuffle", 0, pathbuf);
  80.     options.always_on_top =
  81.         GetPrivateProfileInt("Misc", "Ontop", 0, pathbuf);
  82.     options.auto_exit_after_playing =
  83.         GetPrivateProfileInt("Misc", "Autoexit", 0, pathbuf);
  84.     options.remember_playlist =
  85.         GetPrivateProfileInt("Misc", "Rememberpls", 1, pathbuf);
  86.     options.show_remaining_time =
  87.         GetPrivateProfileInt("Misc", "Remaining", 0, pathbuf);
  88.     options.read_id3_tag =
  89.         GetPrivateProfileInt("Misc", "ReadID3tag", 1, pathbuf);
  90.     options.support_id3v2 =
  91.         GetPrivateProfileInt("Misc", "SuportID3v2", 1, pathbuf);
  92.     options.prefer_native_ogg_tags =
  93.         GetPrivateProfileInt("Misc", "PreferNativeOGGtags", 1, pathbuf);
  94.     options.read_id3_tag_in_background =
  95.         GetPrivateProfileInt("Misc", "BackgroundReadID3", 1, pathbuf);
  96.     options.work_out_track_lengths =
  97.         GetPrivateProfileInt("Misc", "WorkOutTrackLengths", 1, pathbuf);
  98.     options.allow_multiple_instances =
  99.         GetPrivateProfileInt("Misc", "AllowMultipleInstances", 0, pathbuf);
  100.     options.read_id3_tag_of_selected =
  101.         GetPrivateProfileInt("Misc", "ReadSelID3tag", 1, pathbuf);
  102.     options.seconds_delay_after_track =
  103.         GetPrivateProfileInt("Misc", "DelayTime", 0, pathbuf);
  104.     options.decoder_output_mode =
  105.         GetPrivateProfileInt("Misc", "Outputmode", 1, pathbuf);
  106.     options.easy_move =
  107.         GetPrivateProfileInt("Misc", "Easymove", 1, pathbuf);
  108.     options.remember_skin_count =
  109.         GetPrivateProfileInt("Misc", "RememberSkins", 4, pathbuf);
  110.     options.allow_file_once_in_playlist =
  111.         GetPrivateProfileInt("Misc", "Fileonce", 1, pathbuf);
  112.     options.auto_play_when_started =
  113.         GetPrivateProfileInt("Misc", "Autoplay", 0, pathbuf);
  114.     options.show_on_taskbar =
  115.         GetPrivateProfileInt("Misc", "TaskBar", 0, pathbuf);
  116.     options.show_playlist = GetPrivateProfileInt("Misc", "ShowPlaylist", 0, pathbuf);
  117.     options.rotate_systray_icon =
  118.         GetPrivateProfileInt("Misc", "RotateIcon", 1, pathbuf);
  119.     options.scroll_track_title =
  120.         GetPrivateProfileInt("Misc", "Scrolltitle", 1, pathbuf);
  121.     GetPrivateProfileString("Misc", // points to section name
  122.                             "RememberLastSong", // points to key name
  123.                             "", // points to default string
  124.                             options.initial_file, // points to destination buffer
  125.                             MAX_PATH, // size of destination buffer
  126.                             pathbuf); // points to initialization filename
  127.     if(*options.initial_file)
  128.         options.remember_last_played_track = TRUE;
  129.     options.last_selected_skin_number =
  130.         GetPrivateProfileInt("Skin", "LastSkin", 0, pathbuf);
  131.     options.use_default_skin =
  132.         GetPrivateProfileInt("Skin", "UseDefault", 1, pathbuf);
  133.     options.use_playlist_skin =
  134.         GetPrivateProfileInt("Skin", "Useplaylistskin", 0, pathbuf);
  135.     {
  136.         int     teller;
  137.         for (teller = MENU_SKIN_DEFAULT+1; teller < MENU_SKIN_DEFAULT+1 + options.remember_skin_count;
  138.                 teller++) {
  139.             char    SkinFileString[MAX_PATH];
  140.             char    skinpath[MAX_PATH];
  141.             sprintf(SkinFileString, "SkinFile%d", teller - MENU_SKIN_DEFAULT);
  142.             GetPrivateProfileString("Skin", SkinFileString, "",
  143.                                     skinpath, MAX_PATH, pathbuf);
  144.             if (*skinpath != 0) {
  145.                 main_skin_add_to_menu(skinpath);
  146.                 if (options.last_selected_skin_number == teller - MENU_SKIN_DEFAULT) {
  147.                     strcpy(options.main_skin_file, skinpath);
  148.                 }
  149.             }
  150.         }
  151.     }
  152.     GetPrivateProfileString("Skin", "PlaylistSkin", "",
  153.                             options.playlist_skin_file, MAX_PATH, pathbuf);
  154.     options.equalizer =
  155.         GetPrivateProfileInt("Equalizer", "Active", 0, pathbuf);
  156.     for (teller = 1; teller <= 8; teller++) {
  157.         char    keyname[100];
  158.         sprintf(keyname, "Eq%d", teller);
  159.         options.eq_settings[teller] =
  160.             GetPrivateProfileInt("Equalizer", keyname, 0, pathbuf);
  161.     }
  162.     // Read quick find defaults
  163.     {
  164.         char pcQuickFindOption[2];
  165.         GetPrivateProfileString("Misc", "QuickFindSearchTerm", "T", pcQuickFindOption, 2, pathbuf);
  166.         if(pcQuickFindOption[0] == 'M' || pcQuickFindOption[0] == 'm')
  167.             options.m_enQuickFindTerm = qftAlbum;
  168.         else if(pcQuickFindOption[0] == 'A' || pcQuickFindOption[0] == 'a')
  169.             options.m_enQuickFindTerm = qftArtist;
  170.         else
  171.             options.m_enQuickFindTerm = qftTitle;
  172.     }
  173.     // Read mixer mode
  174.     {
  175.         char cMixerMode[32];
  176.         GetPrivateProfileString("Mixer", "Mode", "Master", cMixerMode, 32, pathbuf);
  177.         if(stricmp(cMixerMode, "wave") == 0)
  178.             globals.m_enMixerMode = mmWaveVolume;
  179.         else if(stricmp(cMixerMode, "internal") == 0)
  180.             globals.m_enMixerMode = mmInternal;
  181.         else
  182.             globals.m_enMixerMode = mmMasterVolume;
  183.         globals.m_iVolume = GetPrivateProfileInt("Mixer", "InternalVolume", 60, pathbuf);
  184.     }
  185. }
  186. void    options_write()
  187. {
  188.     char    intbuf[33];
  189.     int     teller;
  190.     char    pathbuf[MAX_PATH];
  191.     int iColIDX;
  192.     main_get_program_path(NULL, pathbuf, MAX_PATH);
  193.     strcat(pathbuf, "coolplayer.ini");
  194.     for(iColIDX = PLAYLIST_first; iColIDX <= PLAYLIST_last; iColIDX++)
  195.     {
  196.         char keyname[100];
  197.         // Write the width
  198.         sprintf(keyname, "PlaylistCol%d", iColIDX);
  199.         WritePrivateProfileString("WindowPos", keyname, _itoa(options.playlist_column_widths[iColIDX], intbuf, 10), pathbuf);
  200.         // Write the order array
  201.         sprintf(keyname, "PlaylistSeq%d", iColIDX);
  202.         WritePrivateProfileString("WindowPos", keyname, _itoa(options.playlist_column_seq[iColIDX], intbuf, 10), pathbuf);
  203.         // Write the visiblity array
  204.         sprintf(keyname, "PlaylistVis%d", iColIDX);
  205.         WritePrivateProfileString("WindowPos", keyname, options.playlist_column_visible[iColIDX] ? "1" : "0", pathbuf);
  206.     }
  207.     WritePrivateProfileString("WindowPos", // pointer to section name
  208.                               "WindowX", // pointer to key name
  209.                               _itoa(options.main_window_pos.x, intbuf, 10), // pointer to string to add
  210.                               pathbuf // pointer to initialization filename
  211.                              );
  212.     WritePrivateProfileString("WindowPos", // pointer to section name
  213.                               "WindowY", // pointer to key name
  214.                               _itoa(options.main_window_pos.y, intbuf, 10), // pointer to string to add
  215.                               pathbuf // pointer to initialization filename
  216.                              );
  217.     WritePrivateProfileString("WindowPos", // pointer to section name
  218.                               "PlaylistX", // pointer to key name
  219.                               _itoa(options.playlist_window_pos.left,
  220.                                     intbuf, 10), // pointer to string to add
  221.                               pathbuf // pointer to initialization filename
  222.                              );
  223.     WritePrivateProfileString("WindowPos", // pointer to section name
  224.                               "PlaylistY", // pointer to key name
  225.                               _itoa(options.playlist_window_pos.top,
  226.                                     intbuf, 10), // pointer to string to add
  227.                               pathbuf // pointer to initialization filename
  228.                              );
  229.     WritePrivateProfileString("WindowPos", // pointer to section name
  230.                               "PlaylistW", // pointer to key name
  231.                               _itoa(options.playlist_window_pos.right -
  232.                                     options.playlist_window_pos.left, intbuf, 10), // pointer to string to add
  233.                               pathbuf // pointer to initialization filename
  234.                              );
  235.     WritePrivateProfileString("WindowPos", // pointer to section name
  236.                               "PlaylistH", // pointer to key name
  237.                               _itoa(options.playlist_window_pos.bottom -
  238.                                     options.playlist_window_pos.top, intbuf, 10), // pointer to string to add
  239.                               pathbuf // pointer to initialization filename
  240.                              );
  241.     WritePrivateProfileString("LastDirectory", // pointer to section name
  242.                               "Directory", // pointer to key name
  243.                               options.last_used_directory, // pointer to string to add
  244.                               pathbuf // pointer to initialization filename
  245.                              );
  246.     WritePrivateProfileString("Skin", "PlaylistSkin",
  247.                               options.playlist_skin_file, pathbuf);
  248.     {
  249.         int     teller;
  250.         int     profileteller = 1;
  251.         char    SkinFileString[MAX_PATH];
  252.         for (teller = MENU_SKIN_DEFAULT+1; teller < MENU_SKIN_DEFAULT+1 + options.remember_skin_count;
  253.                 teller++) {
  254.             if (GetMenuString
  255.                     (globals.main_menu_popup, teller, options.main_skin_file,
  256.                      MAX_PATH, MF_BYCOMMAND)) {
  257.                 if (GetMenuState
  258.                         (globals.main_menu_popup, teller,
  259.                          MF_BYCOMMAND) & MF_CHECKED) {
  260.                     options.last_selected_skin_number = profileteller;
  261.                 }
  262.                 sprintf(SkinFileString, "SkinFile%d", profileteller++);
  263.                 WritePrivateProfileString("Skin", SkinFileString,
  264.                                           options.main_skin_file, pathbuf);
  265.             } else {
  266.                 sprintf(SkinFileString, "SkinFile%d", profileteller++);
  267.                 WritePrivateProfileString("Skin", SkinFileString, NULL,
  268.                                           pathbuf);
  269.             }
  270.         }
  271.     }
  272.     WritePrivateProfileString("Skin", "LastSkin",
  273.                               _itoa(options.last_selected_skin_number,
  274.                                     intbuf, 10), pathbuf);
  275.     WritePrivateProfileString("Skin", "UsePlaylistSkin",
  276.                               _itoa(options.use_playlist_skin, intbuf, 10),
  277.                               pathbuf);
  278.     WritePrivateProfileString("Skin", "UseDefault",
  279.                               _itoa(options.use_default_skin, intbuf, 10),
  280.                               pathbuf);
  281.     WritePrivateProfileString("Misc", "Repeat",
  282.                               _itoa(options.repeat_playlist, intbuf, 10),
  283.                               pathbuf);
  284.     WritePrivateProfileString("Misc", "Shuffle",
  285.                               _itoa(options.shuffle_play, intbuf, 10),
  286.                               pathbuf);
  287.     WritePrivateProfileString("Misc", "Easymove",
  288.                               _itoa(options.easy_move, intbuf, 10),
  289.                               pathbuf);
  290.     WritePrivateProfileString("Misc", "RotateIcon",
  291.                               _itoa(options.rotate_systray_icon, intbuf,
  292.                                     10), pathbuf);
  293.     WritePrivateProfileString("Misc", "Ontop",
  294.                               _itoa(options.always_on_top, intbuf, 10),
  295.                               pathbuf);
  296.     WritePrivateProfileString("Misc", "Autoexit",
  297.                               _itoa(options.auto_exit_after_playing,
  298.                                     intbuf, 10), pathbuf);
  299.     WritePrivateProfileString("Misc", "Rememberpls",
  300.                               _itoa(options.remember_playlist, intbuf, 10),
  301.                               pathbuf);
  302.     WritePrivateProfileString("Misc", "Remaining",
  303.                               _itoa(options.show_remaining_time, intbuf,
  304.                                     10), pathbuf);
  305.     WritePrivateProfileString("Misc", "ReadID3tag",
  306.                               _itoa(options.read_id3_tag, intbuf, 10),
  307.                               pathbuf);
  308.     WritePrivateProfileString("Misc", "ReadSelID3tag",
  309.                               _itoa(options.read_id3_tag_of_selected,
  310.                                     intbuf, 10), pathbuf);
  311.     WritePrivateProfileString("Misc", "SuportID3v2",
  312.                               _itoa(options.support_id3v2, intbuf, 10),
  313.                               pathbuf);
  314.     WritePrivateProfileString("Misc", "PreferNativeOGGtags",
  315.                               _itoa(options.prefer_native_ogg_tags, intbuf, 10),
  316.                               pathbuf);
  317.     WritePrivateProfileString("Misc", "BackgroundReadID3",
  318.                               _itoa(options.read_id3_tag_in_background, intbuf, 10),
  319.                               pathbuf);
  320.     WritePrivateProfileString("Misc", "WorkOutTrackLengths",
  321.                               _itoa(options.work_out_track_lengths, intbuf, 10),
  322.                               pathbuf);
  323.     WritePrivateProfileString("Misc", "AllowMultipleInstances",
  324.                               _itoa(options.allow_multiple_instances, intbuf,
  325.                                     10), pathbuf);
  326.     WritePrivateProfileString("Misc", "Outputmode",
  327.                               _itoa(options.decoder_output_mode, intbuf,
  328.                                     10), pathbuf);
  329.     WritePrivateProfileString("Misc", "Scrolltitle",
  330.                               _itoa(options.scroll_track_title, intbuf,
  331.                                     10), pathbuf);
  332.     WritePrivateProfileString("Misc", "ShowPlaylist",
  333.                               _itoa(options.show_playlist, intbuf, 10),
  334.                               pathbuf);
  335.     {
  336.         if(options.remember_last_played_track)
  337.             WritePrivateProfileString("Misc", "RememberLastSong", options.initial_file, pathbuf);
  338.         else
  339.             WritePrivateProfileString("Misc", "RememberLastSong", "", pathbuf);
  340.     }
  341.     WritePrivateProfileString("Misc", "Fileonce",
  342.                               _itoa(options.allow_file_once_in_playlist,
  343.                                     intbuf, 10), pathbuf);
  344.     WritePrivateProfileString("Misc", "Autoplay",
  345.                               _itoa(options.auto_play_when_started, intbuf,
  346.                                     10), pathbuf);
  347.     WritePrivateProfileString("Misc", "TaskBar",
  348.                               _itoa(options.show_on_taskbar, intbuf, 10),
  349.                               pathbuf);
  350.     WritePrivateProfileString("Misc", "DelayTime",
  351.                               _itoa(options.seconds_delay_after_track,
  352.                                     intbuf, 10), pathbuf);
  353.     WritePrivateProfileString("Misc", "RememberSkins",
  354.                               _itoa(options.remember_skin_count, intbuf,
  355.                                     10), pathbuf);
  356.     WritePrivateProfileString("Equalizer", "Active",
  357.                               _itoa(options.equalizer, intbuf, 10),
  358.                               pathbuf);
  359.     for (teller = 1; teller <= 8; teller++) {
  360.         char    keyname[100];
  361.         sprintf(keyname, "Eq%d", teller);
  362.         WritePrivateProfileString("Equalizer", keyname,
  363.                                   _itoa(options.eq_settings[teller],
  364.                                         intbuf, 10), pathbuf);
  365.     }
  366.     // Write quick find defaults
  367.     {
  368.         char pcQuickFindOption[2];
  369.         pcQuickFindOption[1] = '';
  370.         if(options.m_enQuickFindTerm == qftTitle)
  371.             pcQuickFindOption[0] = 'T';
  372.         else if(options.m_enQuickFindTerm == qftArtist)
  373.             pcQuickFindOption[0] = 'A';
  374.         else if(options.m_enQuickFindTerm == qftAlbum)
  375.             pcQuickFindOption[0] = 'M';
  376.         WritePrivateProfileString("Misc", "QuickFindSearchTerm", pcQuickFindOption, pathbuf);
  377.     }
  378.     // Write out mixer mode
  379.     if(globals.m_enMixerMode == mmMasterVolume)
  380.         WritePrivateProfileString("Mixer", "Mode", "Master", pathbuf);
  381.     else if(globals.m_enMixerMode == mmWaveVolume)
  382.         WritePrivateProfileString("Mixer", "Mode", "Wave", pathbuf);
  383.     else
  384.         WritePrivateProfileString("Mixer", "Mode", "Internal", pathbuf);
  385.     WritePrivateProfileString("Mixer", "InternalVolume", _itoa(globals.m_iVolume, intbuf, 10), pathbuf);
  386. }