replaced duplicate code for updating user level set with function call
[rocksndiamonds.git] / src / editor.c
index 761ff632485f8ebc44968c35d883ca5cf42e6dc0..d78703f3fdb6778df28484b1cd23ea635d65f198 100644 (file)
@@ -2605,13 +2605,13 @@ static struct
   {
     ED_LEVEL_TABS_XPOS(0),             ED_LEVEL_TABS_YPOS(0),
     GADGET_ID_LEVELINFO_LEVEL,         GADGET_ID_NONE,
-    8,                                 "Level",                        
+    8,                                 "Level",
     NULL, NULL, NULL,                  "Configure level properties"
   },
   {
     -1,                                        -1,
     GADGET_ID_LEVELINFO_EDITOR,                GADGET_ID_LEVELINFO_LEVEL,
-    8,                                 "Editor",                       
+    8,                                 "Editor",
     NULL, NULL, NULL,                  "Configure editor properties"
   },
 
@@ -2620,7 +2620,7 @@ static struct
   {
     ED_ELEMENT_TABS_XPOS(0),           ED_ELEMENT_TABS_YPOS(0),
     GADGET_ID_PROPERTIES_INFO,         GADGET_ID_NONE,
-    8,                                 "Info",                 
+    8,                                 "Info",
     NULL, NULL, NULL,                  "Show information about element"
   },
   {
@@ -7508,37 +7508,7 @@ static void ModifyLevelInfoForSavingIntoPersonalLevelSet(char *former_name)
   }
 
   if (level_nr > leveldir_current->last_level)
-  {
-    static char *temp_levelinfo = NULL;
-    FILE *temp_file = NULL;
-    char line[MAX_LINE_LEN];
-
-    setString(&temp_levelinfo,
-             getPath2(getCurrentLevelDir(),
-                      getStringCat2(LEVELINFO_FILENAME, ".new")));
-
-    if ((file = fopen(filename_levelinfo, MODE_READ)) &&
-       (temp_file = fopen(temp_levelinfo, MODE_WRITE)))
-    {
-      while (fgets(line, MAX_LINE_LEN, file))
-      {
-       if (!strPrefix(line, "levels:"))
-         fputs(line, temp_file);
-       else
-         fprintf(temp_file, "%-32s%d\n", "levels:", level_nr + 9);
-      }
-    }
-
-    if (temp_file)
-      fclose(temp_file);
-
-    if (file)
-      fclose(file);
-
-    // needs error handling; also, ok on dos/win?
-    unlink(filename_levelinfo);
-    rename(temp_levelinfo, filename_levelinfo);
-  }
+    UpdateUserLevelSet(getLoginName(), NULL, NULL, level_nr + 9, -1);
 
   // else: allow the save even if annotation failed
 
@@ -8660,6 +8630,24 @@ static void DrawPropertiesTabulatorGadgets()
                  getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
 }
 
+static void PrintInfoText(char *text, int font_nr, int xpos, int ypos)
+{
+  DrawText(SX + xpos, SY + ypos, text, font_nr);
+}
+
+static int PrintElementDescriptionFromFile(char *filename, int font_nr,
+                                          int xpos, int ypos)
+{
+  int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
+  int max_chars_per_line = (SXSIZE - 2 * xpos) / font_width;
+  int max_lines_drawable = (SYSIZE - ypos) / font_height - 1;
+
+  return DrawTextFile(SX + xpos, SY + ypos, filename, font_nr,
+                     max_chars_per_line, -1, max_lines_drawable, 0, -1,
+                     TRUE, FALSE, FALSE);
+}
+
 static void DrawLevelInfoLevel()
 {
   int i;
@@ -8947,24 +8935,6 @@ static void DrawEnvelopeTextArea(int envelope_nr)
   MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
 }
 
-static void PrintInfoText(char *text, int font_nr, int xpos, int ypos)
-{
-  DrawText(SX + xpos, SY + ypos, text, font_nr);
-}
-
-static int PrintElementDescriptionFromFile(char *filename, int font_nr,
-                                          int xpos, int ypos)
-{
-  int font_width = getFontWidth(font_nr);
-  int font_height = getFontHeight(font_nr);
-  int max_chars_per_line = (SXSIZE - 2 * xpos) / font_width;
-  int max_lines_drawable = (SYSIZE - ypos) / font_height - 1;
-
-  return DrawTextFile(SX + xpos, SY + ypos, filename, font_nr,
-                     max_chars_per_line, -1, max_lines_drawable, 0, -1,
-                     TRUE, FALSE, FALSE);
-}
-
 static void DrawPropertiesInfo()
 {
   static struct