]> Dogcows Code - chaz/vimcoder/blobdiff - src/com/dogcows/Editor.java
do not add editor name to the end of a submission
[chaz/vimcoder] / src / com / dogcows / Editor.java
index 203d8ec2eb5ac4dc159205d765f0b628c5cb528c..87403240fa43c7de09fcd36b3035729dabadb312 100644 (file)
@@ -31,6 +31,16 @@ public class Editor
         */
        private String name;
 
+       /**
+        * The name of the contest.
+        */
+       private String contestName;
+
+       /**
+        * The point value.
+        */
+       private String points;
+
        /**
         * The path of the current source file.
         */
@@ -48,10 +58,10 @@ public class Editor
        private static final Map<String,String> languageExtension = new HashMap<String,String>();
        static
        {
-               languageExtension.put("Java", "java");
-               languageExtension.put("C++", "cc");
-               languageExtension.put("C#", "cs");
-               languageExtension.put("VB", "vb");
+               languageExtension.put("Java",   "java");
+               languageExtension.put("C++",    "cc");
+               languageExtension.put("C#",     "cs");
+               languageExtension.put("VB",     "vb");
                languageExtension.put("Python", "py");
        }
 
@@ -68,6 +78,8 @@ public class Editor
        {
                this.id = String.valueOf(component.getProblem().getProblemID());
                this.name = component.getClassName();
+               this.contestName = component.getProblem().getRound().getContestName().replaceAll(" ", "-");
+               this.points = String.valueOf(component.getPoints().intValue());
 
                // Make sure the top-level vimcoder directory exists.
                File topDir = VimCoder.getStorageDirectory();
@@ -77,9 +89,24 @@ public class Editor
                }
 
                // Make sure the problem directory exists.
-               this.directory = new File(topDir, id);
-               if (!directory.isDirectory())
+               File newStyleDirectory = new File(new File(topDir, contestName), points);
+               File oldStyleDirectory = new File(topDir, id);
+               if (newStyleDirectory.isDirectory())
+               {
+                       this.directory = newStyleDirectory;
+               }
+               else if (oldStyleDirectory.isDirectory())
+               {
+                       this.directory = oldStyleDirectory;
+               }
+               else if (VimCoder.isContestDirNames())
+               {
+                       this.directory = newStyleDirectory;
+                       if (!directory.mkdirs()) throw new IOException(directory.getPath());
+               }
+               else
                {
+                       this.directory = oldStyleDirectory;
                        if (!directory.mkdirs()) throw new IOException(directory.getPath());
                }
 
@@ -88,16 +115,17 @@ public class Editor
 
                // Set up the terms used for the template expansion.
                HashMap<String,String> terms = new HashMap<String,String>();
-               terms.put("RETURNTYPE", component.getReturnType().getDescriptor(language));
-               terms.put("CLASSNAME", name);
-               terms.put("METHODNAME", component.getMethodName());
-               terms.put("METHODPARAMS", getMethodParams(component.getParamTypes(),
+               terms.put("RETURNTYPE",           component.getReturnType().getDescriptor(language));
+               terms.put("CLASSNAME",            name);
+               terms.put("METHODNAME",           component.getMethodName());
+               terms.put("METHODPARAMS",         getMethodParams(component.getParamTypes(),
                                                          component.getParamNames(), language));
-               terms.put("METHODPARAMNAMES", Util.join(component.getParamNames(), ", "));
-               terms.put("METHODPARAMSTREAMIN", Util.join(component.getParamNames(), " >> "));
+               terms.put("METHODPARAMNAMES",     Util.join(component.getParamNames(), ", "));
+               terms.put("METHODPARAMSTREAMIN",  Util.join(component.getParamNames(), " >> "));
                terms.put("METHODPARAMSTREAMOUT", Util.join(component.getParamNames(), " << \", \" << "));
-               terms.put("METHODPARAMDECLARES", getMethodParamDeclarations(component.getParamTypes(),
-                                                                           component.getParamNames(), language));
+               terms.put("METHODPARAMDECLARES",  getMethodParamDeclarations(component.getParamTypes(),
+                                                                            component.getParamNames(), language));
+               terms.put("VIMCODER",             VimCoder.version);
 
                // Write the problem statement as an HTML file in the problem directory.
                File problemFile = new File(directory, "Problem.html");
@@ -116,7 +144,7 @@ public class Editor
 
                // Expand the template for the main class and write it to the current
                // source file.
-               sourceFile = new File(directory, name + "." + ext);
+               this.sourceFile = new File(directory, name + "." + ext);
                if (!sourceFile.canRead())
                {
                        String text = Util.expandTemplate(readTemplate(lang + "Template"), terms);
@@ -190,8 +218,7 @@ public class Editor
         */
        public String getSource() throws IOException
        {
-               return Util.readFile(sourceFile) + "\n// Edited by " +
-               VimCoder.version + "\n// " + VimCoder.website + "\n\n";
+               return Util.readFile(sourceFile);
        }
 
 
@@ -236,7 +263,7 @@ public class Editor
                 * before the timeout, we will assume it is not backgrounding and
                 * that everything worked.  This works as long as the Vim server is
                 * able to start within the stall period. */
-               long expire = System.currentTimeMillis() + 1000;
+               long expire = System.currentTimeMillis() + 2500;
                while (System.currentTimeMillis() < expire)
                {
                        Thread.yield();
@@ -327,3 +354,4 @@ public class Editor
        }
 }
 
+// vim:noet:ts=8
This page took 0.023944 seconds and 4 git commands to generate.